/***********************************************************************************************************
 * Name         : CA_AnalystHubHelper
 * Purpose      : Helper methods for caAnalystHub LWC
 **********************************************************************************************************/
public without sharing class CA_AnalystHubHelper {
    /**
     * @description Retrieves all Pro Forma file mapping records along with the
     *  configured sheet name from Config__c custom settings.
     * @return MappingData wrapper containing the list of mappings and the sheet name.
     */
    @AuraEnabled(cacheable=true)
    public static MappingData getMappingData() {
        MappingData result = new MappingData();

        List<CA_Pro_Forma_File_Mapping__c> recs = [
            SELECT Id, Name, Cell_Range__c
            FROM CA_Pro_Forma_File_Mapping__c
            ORDER BY Name ASC
        ];

        result.mappings = new List<MappingRecord>();
        for (CA_Pro_Forma_File_Mapping__c rec : recs) {
            result.mappings.add(new MappingRecord(rec));
        }

        List<Config__c> configs = [
            SELECT Value__c
            FROM Config__c
            WHERE Name = :ConfigUtils.CA_PRO_FORMA_FILE_SHEET
            LIMIT 1
        ];
        result.sheetName = configs.isEmpty() ? null : configs[0].Value__c;

        return result;
    }

    public class MappingData {
        @AuraEnabled
        public List<MappingRecord> mappings;
        @AuraEnabled
        public String sheetName;
    }


    public class MappingRecord {
        @AuraEnabled
        public String id;
        @AuraEnabled
        public String name;
        @AuraEnabled
        public String cellRange;

        public MappingRecord(CA_Pro_Forma_File_Mapping__c rec) {
            this.id = rec.Id;
            this.name = rec.Name;
            this.cellRange = rec.Cell_Range__c;
        }
    }
}
