@isTest
public with sharing class AccountDelayApplyControllerTest {
    static User setNewUser(String firstName, String lastName, String aName, String email) {
		User user = new User(Test_staff__c = true);
        user.LastName = ' ' + lastName;
        user.FirstName = firstName;
        user.Alias = aName;
        user.Email = email;
        user.Username = 'Olympus' + email;
        user.CommunityNickname = aName;
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert user;

        return user;
	}
    @isTest
    static void testAccountDelayApply(){
        // List<Account> HP = [select Id from Account where RecordTypeId = '01210000000QemGAAS' and Is_Active__c = '有効' limit 1];//	病院
        // List<Account> Department_Class_ET = [select Id from Account where RecordTypeId = '01210000000QemQAAS' limit 1];//	戦略科室分類ET
        // List<Account> Agency = [select Id from Account where RecordTypeId = '01210000000Qem1AAC' and Is_Active__c = '有効' limit 1];//  販売店
        // User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com');
        // User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com');
        String rectHp = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        String rectSct = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
        String rectAgency = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        String rectET = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_ET').getRecordTypeId();
        // 病院
        Account HP = new Account(RecordTypeId = rectHp, Name = 'HP');
        HP.Is_Active__c = '有効';
        insert HP;
        // if (Test.isRunningTest()) {
        //     System.runAs(new User(Id = UserInfo.getUserId())){
        //             insert HP;
        //     }
        // }
        //	戦略科室分類ET
        Account Department_Class_ET = new Account(RecordTypeId = rectET, Name = 'Department_Class_ET');
        Department_Class_ET.Is_Active__c = '有効';
        Department_Class_ET.ParentId = HP.id;
        insert Department_Class_ET;
        // if (Test.isRunningTest()) {
        //     System.runAs(new User(Id = UserInfo.getUserId())){
        //             insert Department_Class_ET;
        //     }
        // }
        //  販売店
        Account Agency = new Account(RecordTypeId = rectAgency, Name = 'Agency');
        Agency.Is_Active__c = '有効';
        insert Agency;
        // if (Test.isRunningTest()) {
        //     System.runAs(new User(Id = UserInfo.getUserId())){
        //             insert Agency;
        //     }
        // }
        // Account Department_Class_ET = new Account();//	戦略科室分類ET
        // Department_Class_ET.RecordTypeId = '01210000000QemQAAS';
        // Department_Class_ET.Is_Active__c = '有効';
        // insert Department_Class_ET;
        // Account HP = new Account();//  販売店
        // HP.RecordTypeId = '01210000000QemGAAS';
        // HP.Is_Active__c = '有効';
        // insert HP;
        // List<Account_Delay_Apply__c> b = [select Id from Account_Delay_Apply__c limit 1];
        Test.startTest();
       
        Account_Delay_Apply__c AccQuery = new Account_Delay_Apply__c();
        AccQuery.Is_Active__c = '草案中';
        AccQuery.Hospital__c = HP.Id;
        AccQuery.ChangeReason__c = '地址错误';
        AccQuery.Is_upload_file__c = true;
        AccQuery.InstitutionalType__c = '非医疗机构';
        insert AccQuery;
        // if (Test.isRunningTest()) {
        //     System.runAs(new User(Id = UserInfo.getUserId())){
        //             insert AccQuery;
        //     }
        // }
        System.debug('testAccountDelayApply  : ' + HP);

        AccountDelayApplyController.init(HP.Id);
        
        SubmitAndRefreshController.init(AccQuery.Id);
        SubmitAndRefreshController.init('');

        HosipitalToDeptController.init(HP.Id);
        HosipitalToDeptController.init('');
        HosipitalToDeptController.submitApproval(AccQuery.Id);
        HosipitalToDeptController.submitApproval('');
        HosipitalToDeptController.updataAccount(HP.Id,true);
        HosipitalToDeptController.updataAccount('',true);

        // HosipitalToDeptController.updataAccount(HP.Id,);

        MonthlyClaimsChangeController.init(Agency.Id);
        MonthlyClaimsChangeController.init('');

        CustomLink2AdvancePaymentController.init(Agency.Id);
        CustomLink2AdvancePaymentController.init('');

        NewAgencyContractController.UserInfo_Owner();

        SoakupTeamController.init(Department_Class_ET.Id);
        SoakupTeamController.init('');

        DealerVisitDetailsController.init(HP.Id);
        DealerVisitDetailsController.init('');

        AccountUrlRecordTypeIdController.AccountRecordTypeId('Department_Class_ET');
        // Report report = new Report();
        // List<Report> reportId = [select Id,DeveloperName from Report limit 1];
        // AccountUrlRecordTypeIdController.ReportId(reportId[0].DeveloperName);

        QuolifiedApplySPOController.init(HP.Id);
        QuolifiedApplySPOController.updata(HP.Id);

        AgencyContractCloneController.init();

        toBatchOwnerController.ProfileId();
        toBatchOwnerController.TypeId();

        AccountWebService.toBatchOwner(HP.Id);

        Test.stopTest();
    }
    
}