/*
 * Author: Zhang,Heyang
 * Created Date: 2023/08/07
 * Purpose: get page layout and record data
 * Test Class: LexNewAndEditASEActivityPIPLTest
 *
 * */
public with sharing class LexNewAndEditASEActivityPIPLController {
    @AuraEnabled
    public static ResponseBodyLWC initData(Id rid, String recordTypeId, String sobjectType) {
        Map<String, object> data = new Map<String, object>();
        ResponseBodyLWC rbl = LexNewAndEditBasePIPLController.initData(rid, recordTypeId, sobjectType);
        if(rbl.status == 'Success'){
            data = (Map<String,Object>)rbl.entity;
            data.put('staticResourceContact', Json.serialize(PIHelper.getPIIntegrationInfo('Contact')));
            if(String.isNotBlank(rid)){
                String sql = 'SELECT ReporterASE__r.lastName,ReporterASE__r.AWS_Data_Id__c, ';
                DescribeSObjectResult objectType = rid.getSobjectType().getDescribe();
                List<String> objectFields = new List<String>(objectType.fields.getMap().keySet());
                sql += String.join(objectFields, ',') +' from '+sobjectType+' where id =\''+rid+'\' limit 1';
                System.debug('sql: ' + sql);
                Sobject leadData = Database.query(sql);
                data.put('data',leadData);
            }

            rbl.entity = data;
        }
        return rbl;
    }

    @AuraEnabled
    public static Map<String, Object> getContactByAWSId(String awsId){
        Map<String, Object> resultMap = new Map<String, Object>();
        Contact ContactInfo = new Contact();
        ContactInfo = [SELECT Id,Name,Account.Name,Phone,Email,MobilePhone FROM Contact WHERE AWS_Data_Id__c =:awsId LIMIT 1];
        resultMap.put('ContactInfo', ContactInfo);
        return resultMap;
    }
}