# coding=utf-8
from django.conf import settings
from gm_dbmw_api.descriptor import source, relation
from gm_types.mq.dbmw import DBMWEndPoints

pk_data_source = source.GroupedSource.of(
    source.MySQLTableSource(
        logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
        table_name="api_doctor",
        key_columns=['id'],
        value_columns_excluded=['view_num', 'reply_num', 'new_pm_num', 'reply_pm_num', 'no_reply_pm_num',
                                'share_topic_num', 'last_answered_time'],
        value_columns_all=True,
    ),
    source.RelatedSource(
        source=source.GroupedSource.of(
            source.MySQLTableSource(
                logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
                table_name="api_hospital",
                key_columns=['id'],
                value_columns_excluded=[],
                value_columns_all=True,
            ),
            source.RelatedSource(
                source=source.NullSource(),
                relation=relation.MySQLTableRelation(
                    logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
                    table_name="api_hospital",
                    from_columns=["city_id"],
                    to_columns=["id"],
                )
            )
        ),
        relation=relation.MySQLTableRelation(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_doctor",
            from_columns=["hospital_id"],
            to_columns=["id"],
        )
    ),
    source.RelatedSource(
        source=source.RelatedSource(
            source=source.GroupedSource.of(
                source.MySQLTableSource(
                    logical_database_id=settings.MIMAS_LOGICAL_DATABASE_ID,
                    table_name="api_problem",
                    key_columns=['id'],
                    value_columns_excluded=[],
                    value_columns_all=True,
                ),
                source.RelatedSource(
                    source=source.MySQLTableSource(
                        logical_database_id=settings.MIMAS_LOGICAL_DATABASE_ID,
                        table_name="api_problemtag",
                        key_columns=['id'],
                        value_columns_excluded=[],
                        value_columns_all=True,
                    ),
                    relation=relation.MySQLTableRelation(
                        logical_database_id=settings.MIMAS_LOGICAL_DATABASE_ID,
                        table_name="api_problemtag",
                        from_columns=["id"],
                        to_columns=["problem_id"],
                    )
                )
            ),
            relation=relation.MySQLTableRelation(
                logical_database_id=settings.MIMAS_LOGICAL_DATABASE_ID,
                table_name="api_problem",
                from_columns=["id"],
                to_columns=["user_id"],
            )
        ),
        relation=relation.MySQLTableRelation(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_doctor",
            from_columns=["user_id"],
            to_columns=["id"],
        )
    ),
    source.RelatedSource(
        source=source.MySQLTableSource(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_service",
            key_columns=['id'],
            value_columns_excluded=[],
            value_columns_all=True,
        ),
        relation=relation.MySQLTableRelation(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_service",
            from_columns=["id"],
            to_columns=["doctor_id"],
        )
    ),
    source.RelatedSource(
        source=source.MySQLTableSource(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_doctortag",
            key_columns=['id'],
            value_columns_excluded=[],
            value_columns_all=True,
        ),
        relation=relation.MySQLTableRelation(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_doctortag",
            from_columns=["id"],
            to_columns=["doctor_id"],
        )
    ),
    source.RelatedSource(
        source=source.GroupedSource.of(
            source.MySQLTableSource(
                logical_database_id=settings.MIMAS_LOGICAL_DATABASE_ID,
                table_name="api_diary",
                key_columns=['id'],
                value_columns_excluded=[],
                value_columns_all=True,
            ),
            source.RelatedSource(
                source=source.NullSource(),
                relation=relation.MySQLTableRelation(
                    logical_database_id=settings.MIMAS_LOGICAL_DATABASE_ID,
                    table_name="api_diary_tags",
                    from_columns=["tag_id"],
                    to_columns=["diary_id"],
                )
            )
        ),
        relation=relation.MySQLTableRelation(
            logical_database_id=settings.MIMAS_LOGICAL_DATABASE_ID,
            table_name="api_diary",
            from_columns=["id"],
            to_columns=["doctor_id"],
        )
    ),
    source.RelatedSource(
        source=source.RelatedSource(
            source=source.MySQLTableSource(
                logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
                table_name="api_message",
                key_columns=['id'],
                value_columns_excluded=[],
                value_columns_all=True,
            ),
            relation=relation.MySQLTableRelation(
                logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
                table_name="api_message",
                from_columns=["id"],
                to_columns=["user_id"],
            )
        ),
        relation=relation.MySQLTableRelation(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_doctor",
            from_columns=["user_id"],
            to_columns=["id"],
        )
    ),
    source.RelatedSource(
        source=source.MySQLTableSource(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_ticketsresult",
            key_columns=['id'],
            value_columns_excluded=[],
            value_columns_all=True,
        ),
        relation=relation.MySQLTableRelation(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_ticketsresult",
            from_columns=["id"],
            to_columns=["doctor_id"],
        )
    ),
    source.RelatedSource(
        source=source.MySQLTableSource(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_advertisemanagement",
            key_columns=['id'],
            value_columns_excluded=[],
            value_columns_all=True,
        ),
        relation=relation.MySQLTableRelation(
            logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
            table_name="api_advertisemanagement",
            from_columns=["id"],
            to_columns=["doctor_id"],
        )
    ),
    source.GMMQSource(
        endpoint=DBMWEndPoints.PUNISHMENT_TRIGGER,
    )
)
index_data_source = source.MySQLTableSource(
    logical_database_id=settings.DBMW_LOGICAL_DATABASE_ID,
    table_name="api_doctor",
    key_columns=['id'],
    value_columns_excluded=['view_num', 'reply_num', 'new_pm_num', 'reply_pm_num', 'no_reply_pm_num', 'share_topic_num',
                            'last_answered_time'],
    value_columns_all=True,
)
