import type { SalesforceProduct2WithPricebookEntries } from "../../../catalog/providers/salesforce/raw.types";
import type {
  SalesforceOrderItemRecord,
  SalesforceOrderRecord,
} from "./raw.types";

export interface SalesforceOrderFieldMap {
  order: {
    type: keyof SalesforceOrderRecord;
    activationType: keyof SalesforceOrderRecord;
    activationScheduledAt: keyof SalesforceOrderRecord;
    activationStatus: keyof SalesforceOrderRecord;
    activationErrorCode: keyof SalesforceOrderRecord;
    activationErrorMessage: keyof SalesforceOrderRecord;
    activationLastAttemptAt: keyof SalesforceOrderRecord;
    internetPlanTier: keyof SalesforceOrderRecord;
    installationType: keyof SalesforceOrderRecord;
    weekendInstall: keyof SalesforceOrderRecord;
    accessMode: keyof SalesforceOrderRecord;
    hikariDenwa: keyof SalesforceOrderRecord;
    vpnRegion: keyof SalesforceOrderRecord;
    simType: keyof SalesforceOrderRecord;
    simVoiceMail: keyof SalesforceOrderRecord;
    simCallWaiting: keyof SalesforceOrderRecord;
    eid: keyof SalesforceOrderRecord;
    whmcsOrderId: keyof SalesforceOrderRecord;
    addressChanged: keyof SalesforceOrderRecord;
    billingStreet: keyof SalesforceOrderRecord;
    billingCity: keyof SalesforceOrderRecord;
    billingState: keyof SalesforceOrderRecord;
    billingPostalCode: keyof SalesforceOrderRecord;
    billingCountry: keyof SalesforceOrderRecord;
    mnpApplication: keyof SalesforceOrderRecord;
    mnpReservation: keyof SalesforceOrderRecord;
    mnpExpiry: keyof SalesforceOrderRecord;
    mnpPhone: keyof SalesforceOrderRecord;
    mvnoAccountNumber: keyof SalesforceOrderRecord;
    portingDateOfBirth: keyof SalesforceOrderRecord;
    portingFirstName: keyof SalesforceOrderRecord;
    portingLastName: keyof SalesforceOrderRecord;
    portingFirstNameKatakana: keyof SalesforceOrderRecord;
    portingLastNameKatakana: keyof SalesforceOrderRecord;
    portingGender: keyof SalesforceOrderRecord;
  };
  orderItem: {
    billingCycle: keyof SalesforceOrderItemRecord;
    whmcsServiceId: keyof SalesforceOrderItemRecord;
  };
  product: {
    sku: keyof SalesforceProduct2WithPricebookEntries;
    itemClass: keyof SalesforceProduct2WithPricebookEntries;
    billingCycle: keyof SalesforceProduct2WithPricebookEntries;
    whmcsProductId: keyof SalesforceProduct2WithPricebookEntries;
    internetOfferingType: keyof SalesforceProduct2WithPricebookEntries;
    internetPlanTier: keyof SalesforceProduct2WithPricebookEntries;
    vpnRegion: keyof SalesforceProduct2WithPricebookEntries;
    bundledAddon: keyof SalesforceProduct2WithPricebookEntries;
    isBundledAddon: keyof SalesforceProduct2WithPricebookEntries;
  };
}

export type PartialSalesforceOrderFieldMap = {
  [Section in keyof SalesforceOrderFieldMap]?: Partial<SalesforceOrderFieldMap[Section]>;
};

export const defaultSalesforceOrderFieldMap: SalesforceOrderFieldMap = {
  order: {
    type: "Type",
    activationType: "Activation_Type__c",
    activationScheduledAt: "Activation_Scheduled_At__c",
    activationStatus: "Activation_Status__c",
    activationErrorCode: "Activation_Error_Code__c",
    activationErrorMessage: "Activation_Error_Message__c",
    activationLastAttemptAt: "Activation_Last_Attempt_At__c" as keyof SalesforceOrderRecord,
    internetPlanTier: "Internet_Plan_Tier__c",
    installationType: "Installment_Plan__c",
    weekendInstall: "Weekend_Install__c",
    accessMode: "Access_Mode__c",
    hikariDenwa: "Hikari_Denwa__c",
    vpnRegion: "VPN_Region__c",
    simType: "SIM_Type__c",
    simVoiceMail: "SIM_Voice_Mail__c",
    simCallWaiting: "SIM_Call_Waiting__c",
    eid: "EID__c",
    whmcsOrderId: "WHMCS_Order_ID__c",
    addressChanged: "Address_Changed__c",
    billingStreet: "BillingStreet",
    billingCity: "BillingCity",
    billingState: "BillingState",
    billingPostalCode: "BillingPostalCode",
    billingCountry: "BillingCountry",
    mnpApplication: "MNP_Application__c",
    mnpReservation: "MNP_Reservation_Number__c",
    mnpExpiry: "MNP_Expiry_Date__c",
    mnpPhone: "MNP_Phone_Number__c",
    mvnoAccountNumber: "MVNO_Account_Number__c",
    portingDateOfBirth: "Porting_Date_Of_Birth__c",
    portingFirstName: "Porting_First_Name__c",
    portingLastName: "Porting_Last_Name__c",
    portingFirstNameKatakana: "Porting_First_Name_Katakana__c",
    portingLastNameKatakana: "Porting_Last_Name_Katakana__c",
    portingGender: "Porting_Gender__c",
  },
  orderItem: {
    billingCycle: "Billing_Cycle__c",
    whmcsServiceId: "WHMCS_Service_ID__c",
  },
  product: {
    sku: "StockKeepingUnit",
    itemClass: "Item_Class__c",
    billingCycle: "Billing_Cycle__c",
    whmcsProductId: "WH_Product_ID__c",
    internetOfferingType: "Internet_Offering_Type__c",
    internetPlanTier: "Internet_Plan_Tier__c",
    vpnRegion: "VPN_Region__c",
    bundledAddon: "Bundled_Addon__c",
    isBundledAddon: "Is_Bundled_Addon__c",
  },
};

export function createSalesforceOrderFieldMap(
  overrides: PartialSalesforceOrderFieldMap = {}
): SalesforceOrderFieldMap {
  return {
    order: { ...defaultSalesforceOrderFieldMap.order, ...overrides.order },
    orderItem: { ...defaultSalesforceOrderFieldMap.orderItem, ...overrides.orderItem },
    product: { ...defaultSalesforceOrderFieldMap.product, ...overrides.product },
  };
}

