export var emailId = undefined;
export var name = undefined;
export var phoneNo = undefined;
export var panHolderName = undefined;
export var panNo = undefined;
export var agentNumber = undefined;

export function getUserDetails(realm){
    try {
      var AppLoginStatus = realm.objects("AppLoginStatus");
      if (AppLoginStatus === undefined || AppLoginStatus[0] === undefined) {
        throw new Error("We are unable to find your details!");
      }else if(AppLoginStatus[0].userType === "Customer"){ // Customer logged-in
        const RealmCustomerDetails = realm.objects("CustomerDetails");
        phoneNo= RealmCustomerDetails[0]?.mobileNumber,
        emailId= RealmCustomerDetails[0]?.email,
        name=RealmCustomerDetails[0]?.name       
      }else if(AppLoginStatus[0].userType === "DealerOrAgent"){ // DearlerOrAgent logged-in
        const agentData = realm.objects("AgentDetails");
        name= agentData[0]?.name;
        emailId= agentData[0]?.emailId;
        phoneNo= agentData[0]?.phoneNo;
         panHolderName = agentData[0]?.panHolderName;
        panNo = agentData[0]?.panNo;
        agentNumber = agentData[0]?.agentNumber;
        }else{ // OEM Dealer logged-in
        const oemDealerInfo = realm.objects("OEMDealerInfo");
        
        // agentNumber =oemDealerInfo[0]?.dealerCode;
        name =oemDealerInfo[0]?.dealerName;
       agentNumber =oemDealerInfo[0]?.agentCode;
        // =oemDealerInfo[0]?.agentName;
        emailId=oemDealerInfo[0]?.email;
        phoneNo=oemDealerInfo[0]?.mobileNumber;
        // emailId=oemDealerInfo[0]?.runnerEmail;
        // phoneNo=oemDealerInfo[0]?.runnerMobile;
        // name=oemDealerInfo[0]?.runnerName;
      }
    } catch (error) {
        throw new Error("getUserDetails "+error)
    }
}


export default {getUserDetails,emailId, name, phoneNo, panHolderName, panNo, agentNumber};