@isTest
public with sharing class SyncProvinceWIndowToSignFormTest {
    @isTest
    private static void testTestCase() {
        // Test data setup
        //新建电子签收单
        map<string, eSignForm__c> eSFMap = new Map<string, eSignForm__c>();
        eSignForm__c eSignForm = new eSignForm__c();
        eSignForm.Name = '::测试电子签收单';
        eSignForm.DNName__c = '112233';
        eSFMap.put(eSignForm.DNName__c, eSignForm);

        Statu_Achievements_DN__c sad = new Statu_Achievements_DN__c();
        sad.Name = '112233';
        sad.DeliveryDate_Raw__c = '1111';
        sad.Sales_assistant_name_text__c = UserInfo.getUserId();
        sad.RC_Manager__c = UserInfo.getUserId();
        sad.EsignTestAccount__c = true;
        sad.ReturnMark__c = false;

        list<Statu_Achievements_DN__c> DNList = new List<Statu_Achievements_DN__c>();
        DNList.add(sad);

        List<RecordType> rectCo = [SELECT Id FROM RecordType WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [
            SELECT Id
            FROM RecordType
            WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '戦略科室分類 呼吸科'
        ];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [SELECT Id FROM RecordType WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }

        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name = 'TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name = '*';
        depart.Department_Name__c = 'TestDepart';
        depart.ParentId = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c = company.Id;
        upsert depart;

        RecordType rectOpp = [
            SELECT id
            FROM RecordType
            WHERE IsActive = TRUE AND SobjectType = 'Opportunity' AND DeveloperName = 'Opportunity'
        ];
        Opportunity opp = new Opportunity(
            Name = 'testOpp1',
            StageName = '引合',
            CloseDate = Date.today(),
            AccountId = depart.Id,
            Sales_Root__c = '販売店',
            Competitor__c = 'A',
            Click_Close_Date__c = null,
            RecordType = rectOpp
        );
        insert opp;

        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );
        insert Sac;
        list<eSignForm__c> esignFormTest = DNUpsertBatch.SetupeSignForm(eSFMap, DNList);
        esignFormTest[0].Statu_Achievements__c = Sac.Id;
        insert esignFormTest;
        system.debug('Test esignForm Data:' + esignFormTest);

        OCM_Management_Province__c ocsmTest = new OCM_Management_Province__c();
        ocsmTest.Name = '其他';
        ocsmTest.Province__c = '北京市';
        insert ocsmTest;
        ocsmTest.Window1__c = Userinfo.getUserId();
        update ocsmTest;

        // Actual test
        Test.startTest();
        //SyncProvinceWIndowToSignForm.syncProvinceWIndow(new Set<String>{'北京市'});
        //SyncProvinceWIndowToSignForm.syncProvinceWIndow(new Set<String>());
        Test.stopTest();

        // Asserts
    }
}
