/*
 * Author: Cuiping Su
 * Created Date: 03/01/2022
 * Purpose: Utility class for describe layouts
 * Test Class: NewAndEditRepairController
 * History: 
 *      03/01/2022 - Cuiping Su - Initial Code.
 * 
 * */
global class NewAndEditRepairController extends NewAndEditBaseController {
	
    public String contactAWSDataId {get; set;}
    public String contactName{get; set;}
    public String contactPhone {get; set;}
    public Repair__c repair{get; set;}
    public String staticResourceContact {get; set;}
    public NewAndEditRepairController(ApexPages.StandardController controller){
        
        List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Repair__c').getDescribe().fields.getMap().keyset());  
        // Add fields to controller. This is to avoid the SOQL error in visualforce page
        //Get Account Id from url param
    
        // System.debug('accountType = ' + );
        if(!Test.isRunningTest()){
            controller.addFields(fieldList);
        }
        Init(controller.getRecord());

        staticResourceContact = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact'));

        SObject obj = controller.getRecord();
        if(obj != null){
            System.debug('obj.Id = ' + obj.Id);
            repair = [Select Id, ContactD__c From Repair__c WHERE ID =:obj.Id];
            if (repair.ContactD__c != null) {
                System.debug('repair.ContactD__c = ' + repair.ContactD__c);
                Contact contact = [SELECT ID, AWS_Data_Id__c, Name, Phone FROM Contact WHERE ID =:repair.ContactD__c];
                System.debug('contact.AWS_Data_Id__c = ' + contact.AWS_Data_Id__c );
                contactAWSDataId = contact.AWS_Data_Id__c;
                contactName = contact.Name;
                contactPhone = contact.Phone;
            }
        }
    }
    @RemoteAction
    global static Response saveRepair(String RepairJson, String transId, Boolean isNew){
        if(Test.isRunningTest()){
            return new Response();
        }
        return save(new Repair__c(), RepairJson, transId, isNew);
    }
}