@IsTest
private class AppraiserCaseDocGenServiceTest {
    @IsTest
    static void buildsPayloadAndRequestJson() {
        Appraiser_Case__c appraiserCase = new Appraiser_Case__c(
            Appraiser_Field_Review_Date__c = Date.newInstance(2026, 4, 1),
            Property_Street__c = '123 Main St',
            Property_City__c = 'Ottawa',
            Property_State_Province__c = 'ON',
            Property_Postal_Code__c = 'K1A 0A1',
            Property_Country__c = 'Canada'
        );
        insert appraiserCase;

        insert new Appraiser_Deficiency__c(
            Name = 'Deficiency 1',
            Appraiser_Case__c = appraiserCase.Id,
            Deficiency_Number__c = '1',
            Description__c = 'Missing comparable sale analysis',
            Resolution__c = 'Provide updated comparable sales section',
            Sort_Order__c = 1
        );

        Test.startTest();
        AppraiserCaseDocGenService.AppraiserCasePayload payload = AppraiserCaseDocGenService.buildPayload(appraiserCase.Id);
        String json = AppraiserCaseDocGenService.buildDocGenRequestJson(appraiserCase.Id, 'APPRAISER_REVIEW_LETTER');
        Test.stopTest();

        System.assertEquals(appraiserCase.Id, payload.caseId);
        System.assertEquals('Ottawa', payload.propertyCity);
        System.assertEquals(1, payload.deficiencies.size());
        System.assertEquals('1', payload.deficiencies[0].deficiencyNumber);
        System.assert(json.contains('APPRAISER_REVIEW_LETTER'));
        System.assert(json.contains('Missing comparable sale analysis'));
    }
}
