using PoJun.Dapper;
using ASHermed.SinoInterface.Api.IRepository.Test;
using ASHermed.SinoInterface.Entity.Test;
using ASHermed.SinoInterface.Repository.MySql;
using ASHermed.SinoInterface.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ASHermed.SinoInterface.Api.ContractModel.App;
using ASHermed.SinoInterface.Api.IRepository;

namespace ASHermed.SinoInterface.Api.MySqlRepository
{

    public class DicMapHisDoctorRepository : BaseRepositoryToASHermed_SinoInterface<Dic_Map_His_Doctor>, IDicMapHisDoctorRepository
    {
        public List<HosByLanguage> SelectByDoctorByLanguage(int doctorId, int language, int useOccasionType)
        {
            var selectSql = new StringBuilder();
            if (language == 1)
            {
                selectSql.Append(@"select distinct t1.ID,t1.CN_ABBREVIATED_ADDR AS NAME,CN_ADDR as Addr ");
            }
            else
            {
                selectSql.Append(@"select distinct t1.ID,t1.EN_ABBREVIATED_ADDR AS NAME,EN_ADDR as Addr ");
            }
            selectSql.Append(@" from dic_hos t1, dic_map_dept_doctor t2
                            where t1.IS_DELETED = false AND t1.ID = t2.APT_HOS_ID AND t2.IS_DELETED = false
                            AND t2.USE_OCCASION =@useOccasion
                            AND t2.APT_DOCTOR_ID = @doctorId");
            var parms = new Dictionary<string, object>();
            parms.Add("@useOccasion", useOccasionType);
            parms.Add("@doctorId", doctorId);
            var result = Query<HosByLanguage>(selectSql.ToString(), parms);
            return result?.ToList();
        }

        public List<DeptByLanguage> SelectByDoctorByLanguage(int doctorId, int language)
        {
            var selectSql = new StringBuilder();
            if (language == 1)
            {
                selectSql.Append(@"select distinct t1.ID, t1.CN_NAME as NAME,t1.LIST_IMAGE ");
            }
            else
            {
                selectSql.Append(@"select distinct t1.ID, t1.EN_NAME as NAME,t1.LIST_IMAGE ");
            }
            selectSql.Append(@" from dic_dept t1, dic_map_dept_doctor t2
                                where t1.IS_DELETED = false and t1.DEPT_TYPE=0 AND t1.ID = t2.APT_DEPT_ID AND t2.IS_DELETED = false
                                AND t2.USE_OCCASION = 0
                                AND t2.APT_DOCTOR_ID = @doctorId");
            var parms = new Dictionary<string, object>();
            parms.Add("@doctorId", doctorId);
            var result = Query<DeptByLanguage>(selectSql.ToString(), parms);
            return result?.ToList();
        }

        public Dic_Map_His_Doctor SelectByDoctor(int doctorId)
        {
            var selectSql = new StringBuilder();

            selectSql.Append(@"select ID, APT_DOCTOR_ID, HIS_HOS_ID, HIS_DEPT_ID, HIS_DOCTOR_ID,HIS_DOCTOR_CODE, CARE_PROV_ID, APT_TYPE,IS_DELETED
                                from dic_map_his_doctor
                                where IS_DELETED = false
                                and APT_DOCTOR_ID = @doctorId");

            var parms = new Dictionary<string, object>();
            parms.Add("@doctorId", doctorId);
            var result = Query<Dic_Map_His_Doctor>(selectSql.ToString(), parms);
            return result?.FirstOrDefault();
        }

        

    }
}
