public class OtherButtonOppCtl {

    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new initData();
        try{
            Opportunity opp =  [SELECT Id,CurrencyIsoCode,StageName,Estimation_Decision__c,SAP_Send_OK__c,If_Authorizing_Lock__c,
                                Agency1__c,Agency1_ID_18__c,Agency_Opportunity__c,Trade__c,Name,Close_Forecasted_Date__c,Opportunity_stage__c,
                                Bid_Planned_Date__c,Wholesale_Price__c,Opportunity_Category__c FROM Opportunity WHERE Id =: recordId LIMIT 1];
            System.debug(LoggingLevel.INFO, '*** opp: ' + opp);
            res.currencyIsoCode = opp.CurrencyIsoCode;
            res.stageName = opp.StageName;
            res.estimationDecision = opp.Estimation_Decision__c;
            res.SAPSendOK = opp.SAP_Send_OK__c;
            res.IfAuthorizingLock = opp.If_Authorizing_Lock__c;
            res.agency1Id = opp.Agency1_ID_18__c;
            res.agencyOpportunity = opp.Agency_Opportunity__c;
            res.trade = opp.Trade__c;
            res.oppName = opp.Name;
            res.opp = opp;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }

    @AuraEnabled
    public static List<Agency_Hospital_Link__c> selectAgencyHospital(String recordId){
        List<Agency_Hospital_Link__c> res = new List<Agency_Hospital_Link__c>();
        try{
            Opportunity opp =  [SELECT Id,Agency1_ID_18__c,Hospital__c FROM Opportunity WHERE Id =: recordId LIMIT 1];
            res = [SELECT Id, Name FROM Agency_Hospital_Link__c WHERE Agency__c =:opp.Agency1_ID_18__c AND Hospital__c =:opp.Hospital__c];
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }

    @AuraEnabled
    public static List<RecordType> selectRecordType(){
        List<RecordType> res = new List<RecordType>();
        try{
            res = [SELECT Id, Name FROM RecordType WHERE SobjectType='Agency_Opportunity__c' And developerName='Opportunity' And IsActive = TRUE];
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    @AuraEnabled
    public static List<FieldDefinition> selectFieldDefinition(){
        List<FieldDefinition> res = new List<FieldDefinition>();
        try{
            res = [Select QualifiedApiName, EntityDefinition.KeyPrefix, DurableId From FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Agency_Opportunity__c'];
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    

    public class ReturnData{
        @AuraEnabled
        public String status;
        @AuraEnabled
        public Object data;

        public void ReturnData(){
            status = 'Fail';
        }
    }
    public class InitData{
        @AuraEnabled
        public String currencyIsoCode;
        @AuraEnabled
        public String stageName;
        @AuraEnabled
        public Boolean estimationDecision;
        @AuraEnabled
        public Boolean SAPSendOK;
        @AuraEnabled
        public Boolean IfAuthorizingLock;
        @AuraEnabled
        public String agency1Id;
        //  Agency_Opportunity__c
        @AuraEnabled
        public String agencyOpportunity;
        @AuraEnabled
        public String trade;
        @AuraEnabled
        public String oppName;
        @AuraEnabled
        public Opportunity opp;
    }

}