# -*- encoding: utf8 -*

from talos.backbone.rpc import RPCMixin

rpc_invoker = RPCMixin.get_remote_rpc_invoker()

# topic 迁移二期，未调用 ， 故注释 20180125
# def get_doctor_diary_info(doctor_ids):
#     results = {
#         doctor_id: {
#             'doctor_id': doctor_id,
#             'diary_count': 0,
#             'diary_tags':[],
#         } for doctor_id in doctor_ids
#     }
#     diaries = rpc_invoker['talos/diary/list_by_doctor_ids'](doctor_ids=doctor_ids, diary_id_only=True)
#     diaries = diaries.unwrap()
#     for diary in diaries:
#         results[diary['doctor_id']]['diary_count'] = len(diary['diaries'])
#         if not diary['diaries']:
#             continue
#         diary_ids = [d['id'] for d in diary['diaries']]
#         tag_map = {}
#         diary_tags = rpc_invoker['talos/diary/diary_tags_by_diary_ids'](diary_ids=diary_ids)
#         diary_tags = diary_tags.unwrap()
#         for diary_tag in diary_tags:
#             for t in diary_tag['tags']:
#                 if t['id'] not in tag_map:
#                     tag_map[t['id']] = t
#         results[diary['doctor_id']]['diary_tags'] = tag_map.values()
#     return results.values()



def get_service_diary_count(service_ids):
    results = rpc_invoker['diary/diary_info_by_service_ids'](service_ids=service_ids, count_only=True)
    return results.unwrap()
