public with sharing class lexConsumApply_FromRACtl {
    public lexConsumApply_FromRACtl() {

    }

    @AuraEnabled
    public static List<FieldDefinition> fieldDefineApp(){
        try {
            List<FieldDefinition> rep = [Select QualifiedApiName, EntityDefinition.KeyPrefix, DurableId From FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Consum_Apply__c'];
            return rep;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

    //获取当前登录人的 id
    @AuraEnabled
    public static UserResult UserInfo_Owner() {
        UserResult result = new UserResult();
        ID myUserID = UserInfo.getUserId();
        try { 
            User tempUser =
                [select Id,isFormal_Stuff__c,FirstName,LastName from user where id = : myUserID ];
            result.id = tempUser.Id;
            result.isFormalStuff = tempUser.isFormal_Stuff__c;
            result.firstName = tempUser.FirstName == null ? '' : tempUser.FirstName;
            result.lastName = tempUser.LastName == null ? '' : tempUser.LastName;
        } catch (exception e) {
            
            result.result = e.getMessage();
        }
        return result;
    }

    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new initData();
        try {
            Rental_Apply__c rep = [select Id,demo_purpose2__c,Campaign__c,QIS_number__c,QISRepair__c,OPD__c,OPDPlan__c,Hospital__c,Strategic_dept__c,Account__c,ApplyPerson_Phone__c,Phone_number__c,Request_shipping_day__c,Loaner_medical_Staff__c,Loaner_medical_Staff__r.AWS_Data_Id__c,Loaner_medical_Staff__r.Name,AWS_Data_Id__c,Shipment_address__c,Dealer__c,direct_send__c,pickup_time__c,Loaner_received_staff__c,Loaner_received_staff_phone__c,Post_Code__c,direct_shippment_address__c from Rental_Apply__c where Id =: recordId]; //deloitte 2023/08/04 zhj 加上字段Loaner_medical_Staff__r.AWS_Data_Id__c,Loaner_medical_Staff__r.Name,AWS_Data_Id__c
            res.rentalApplyId = rep.Id;
            res.demoPurpose2 = '';
            res.rentalCampaign = rep.Campaign__c == null ? '' : rep.Campaign__c;
            res.rentalQISNumber = rep.QIS_number__c == null ? '' : rep.QIS_number__c;
            res.rentalQISRepair = rep.QISRepair__c == null ? '' : rep.QISRepair__c;
            res.rentalOPD = rep.OPD__c == null ? '' : rep.OPD__c;
            res.rentalOPDPlan = rep.OPDPlan__c == null ? '' : rep.OPDPlan__c;
            res.rentalHospital = String.isBlank(rep.Hospital__c) ? '' : rep.Hospital__c;
            res.rentalStrategicDept = rep.Strategic_dept__c == null ? '' : rep.Strategic_dept__c;
            res.rentalAccount = rep.Account__c == null ? '' : rep.Account__c;
            res.rentalApplyPersonPhone = rep.ApplyPerson_Phone__c == null ? '' : rep.ApplyPerson_Phone__c;
            res.rentalPhoneNumber = rep.Phone_number__c == null ? '' : rep.Phone_number__c;
            res.rentalRequestShippingDay = rep.Request_shipping_day__c;
            res.rentalLoanerMedicalStaff = rep.Loaner_medical_Staff__c == null ? '' : rep.Loaner_medical_Staff__c;
            res.rentalShipmentAddress = rep.Shipment_address__c == null ? '' : rep.Shipment_address__c;
            res.rentalDealer = rep.Dealer__c == null ? '' : rep.Dealer__c;
            res.rentalDirectSend = rep.direct_send__c == null ? '' : rep.direct_send__c;
            res.rentalPickupTime = rep.pickup_time__c;
            res.rentalLoanerReceivedStaff = rep.Loaner_received_staff__c == null ? '' : rep.Loaner_received_staff__c;
            res.rentalLoanerReceivedStaffPhone = rep.Loaner_received_staff_phone__c == null ? '' : rep.Loaner_received_staff_phone__c;
            res.rentalPostCode = rep.Post_Code__c == null ? '' : rep.Post_Code__c;
            res.rentalDirectShippmentAddress = rep.direct_shippment_address__c == null ? '' : rep.direct_shippment_address__c;
            res.rentalLoanerMedicalStaffName = rep.Loaner_medical_Staff__r.Name == null ? '' : rep.Loaner_medical_Staff__r.Name;//deloitee-zhj 20230804
            res.rentalLoanerMedicalStaffAWSDataId = rep.Loaner_medical_Staff__r.AWS_Data_Id__c == null ? '' : rep.Loaner_medical_Staff__r.AWS_Data_Id__c;//deloitee-zhj 20230804
            res.rentalApplyAWSDataId = rep.AWS_Data_Id__c == null ? '' : rep.AWS_Data_Id__c;//deloitee-zhj 20230804 
            if(rep.demo_purpose2__c == '试用（有询价）' || rep.demo_purpose2__c == '试用（无询价）'){
                res.demoPurpose2 = 'OPD试用';
            }else if(rep.demo_purpose2__c == '学会展会'){
                res.demoPurpose2 = '学会展会';
            }else if(rep.demo_purpose2__c == '索赔QIS'){
                res.demoPurpose2 = '索赔QIS';
            }
            return res;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
    public class InitData{
        @AuraEnabled
        public String rentalApplyId;
        @AuraEnabled
        public String demoPurpose2;
        @AuraEnabled
        public String rentalCampaign;
        @AuraEnabled
        public String rentalQISNumber;
        @AuraEnabled
        public String rentalQISRepair;
        @AuraEnabled
        public String rentalOPD;
        @AuraEnabled
        public String rentalOPDPlan;
        @AuraEnabled
        public String rentalHospital;
        @AuraEnabled
        public String rentalStrategicDept;
        @AuraEnabled
        public String rentalAccount;
        @AuraEnabled
        public String rentalApplyPersonPhone;
        @AuraEnabled
        public String rentalPhoneNumber;
        @AuraEnabled
        public Date rentalRequestShippingDay;
        @AuraEnabled
        public String rentalLoanerMedicalStaff;
        @AuraEnabled
        public String rentalShipmentAddress;
        @AuraEnabled
        public String rentalDealer;
        @AuraEnabled
        public String rentalDirectSend;
        @AuraEnabled
        public Datetime rentalPickupTime;
        @AuraEnabled
        public String rentalLoanerReceivedStaff;
        @AuraEnabled
        public String rentalLoanerReceivedStaffPhone;
        @AuraEnabled
        public String rentalPostCode;
        @AuraEnabled
        public String rentalDirectShippmentAddress;
        @AuraEnabled
        public String rentalLoanerMedicalStaffName;//deloitee-zhj 20230804
        @AuraEnabled
        public String rentalLoanerMedicalStaffAWSDataId;//deloitee-zhj 20230804
        @AuraEnabled
        public String rentalApplyAWSDataId;//deloitee-zhj 20230804
    }

    public class UserResult {
        @AuraEnabled
        public string result;
        public UserResult( ) {
            result = 'Success';
        }
        @AuraEnabled
        public string id;
        @AuraEnabled
        public Boolean isFormalStuff;
        @AuraEnabled
        public string firstName;
        @AuraEnabled
        public string lastName;
    }
}