import { CashBack } from "./shoppingCart";

export enum OrderItemStatusEnum {
  PENDING = "pending",
  PURCHASED = "purchased",
  CANCELLED = "cancelled",
  REFUNDED = "refunded",
  FAILED = "failed",
}

export interface IOrderItems {
  name: string;
  featureImage: string;
  quantity: number;
  price: number;
  discount: number;
  categoryCode: string;
  shipmentStatus: string;
  categoryId: number;
  categoryName: string;
  totalCostOfShipment: string;
  oneCareIncluded?: boolean;
  sku?: string;
  utilityToken?: string;
  smartPayPercentage?: string;
  smartPayOriginalPrice?: string;
  isReturned?: boolean;
  shipmentItem?: {
    name: string;

    featureImage: string;
    quantity: number;
    price: number;
    categoryCode: string;
    categoryId: number;
    categoryName: string;
    shipmentStatus?: string;

    orderItem?: {
      name: string;
      featureImage: string;
      quantity: number;
      price: number;
      categoryCode: string;
      categoryId: number;
      categoryName: string;
    };
  };
  shipmentItems?: {
    name: string;
    shipmentItemIdentifier?: string;

    featureImage: string;
    quantity: number;
    price: number;
    categoryCode: string;
    categoryId: number;
    categoryName: string;
    shipmentStatus?: string;

    orderItem?: {
      name: string;
      featureImage: string;
      quantity: number;
      price: number;
      categoryCode: string;
      categoryId: number;
      categoryName: string;
    };
  }[];
  enforcedShippingItems?: {
    name: string;
    featureImage: string;
    quantity: number;
    price: number;
    categoryCode: string;
    categoryId: number;
    categoryName: string;
    shipmentStatus?: string;

    orderItem?: {
      name: string;
      featureImage: string;
      quantity: number;
      price: number;
      categoryCode: string;
      categoryId: number;
      categoryName: string;
    };
  }[];
  kitData?: kitItem[];
  isUpgradable?: boolean;
  status: OrderItemStatusEnum;
  unitPrice?: number;
  unitDiscount?: number;
  nlkAllocationsPerUnit?: number;
  unitOriginalPrice?: number;
}

export type kitItem = {
  name: string;
  shipmentItemIdentifier: string;
  shipmentStatus: string;
  categoryName?: string;
};

export type IOrderPaymentMethod = {
  id: number;
  code: string;
  name: string;
};

export type IOrderBillingAddress = {
  id: number;
  city: string;
  email: string;
  phone: string;
  state: string;
  address: string;
  buildingInfo: string;
  type: string;
  country: {
    name: string;
    code: string;
    flag: string;
  };
  lastName: string;
  latitude: string;
  firstName: string;
  longitude: string;
  postalCode: string;
  countryCode: string;
};

export type IAssetOption = {
  id: number;
  cartId: number;
  createdAt: Date;
  updatedAt: Date;
  assetOption: {
    id: number;
    name: string;
    symbol: string;
    isActive: boolean;
    optionId: number;
    provider: string;
    createdAt: Date;
    deletedAt: null;
    isDeleted: boolean;
    updatedAt: Date;
    isVariable: boolean;
    optionName: string;
    displayOrder: number;
    optionSymbol: string;
    isAssetActive: true;
    minPercentage: number;
    optionIsActive: boolean;
    paymentMethodId: number;
    isCommissionEnabled: boolean;
    commissionMultiplier: {
      base: {
        cv: number;
        vp: number;
      };
      option: {
        cv: number;
        vp: number;
      };
    };
  };
  baseAssetName: string;
  baseAssetAmount: string;
  baseAssetSymbol: string;
  optionAssetName: string;
  optionAssetAmount: number;
  optionAssetSymbol: string;
  baseAssetPercentage: number;
  calculatedCommision: {
    base: {
      cv: number;
      vp: number;
    };
    option: {
      cv: number;
      vp: number;
    };
    totalCV: number;
    totalVP: number;
  };
  optionAssetPercentage: number;
};

export interface IOrder {
  id: number;
  orderId: string;
  shipmentOrderId?: string;
  orderItems?: IOrderItems[];
  orderUpgrades?: OrderUpgrade[];
  shipmentOrderItems?: IOrderItems[];
  paymentMethod: IOrderPaymentMethod;
  billingAddress: IOrderBillingAddress;
  shippingAddress?: IOrderBillingAddress;
  shippingMethod?: ShippingMethod;
  store?: Store;
  paymentBillingAddress: IOrderBillingAddress;
  subTotal: number;
  vatTotal: number;
  grandTotal: number;
  feesTotal: number;
  taxTotal: number;
  discountTotal: number;
  shippingTotal: number;
  status: string;
  paymentStatus: string;
  createdAt: Date;
  updatedAt: Date;
  assetOption: IAssetOption;
  fees: Fee[];
  taxes: Tax[];
  isSmartPay?: boolean;
  isUpgradable?: boolean;
  cashBacks?: CashBack[];
  orderInvoice?: ShipmentOrderInvoice;
  shipmentOrderInvoice?: ShipmentOrderInvoice;
  enforcedShipping: boolean;
  productBoost?: string;
  isUpgrade: boolean;
  isSoftwareOnly?: boolean;
  creditNotes?: CreditNote[];
}

type CreditNote = {
  id: number;
  identifier: string;
  createdFor: "order" | "shipment"; // Using union type for specific values
  type: "refund" | string; // Add other possible types if needed
  createdAt: string;
  updatedAt: string;
  creditNoteInvoiceFileName: string;
  orderId: number;
  shipmentOrderId: number | null;
  creditNoteInvoiceUrl: string;
};

type ShipmentOrderInvoice = {
  createdAt: string;
  id: number;
  invoiceFileName: string | null;
  invoiceSequenceNumber: number;
  invoiceUrl: string | null;
  shipmentOrderId: number;
  updatedAt: string;
};

type Fee = {
  amount: string;
  cartId: number;
  feeCategory: string;
  feeName: string;
  id: number;
  type: string;
  value: string;
};

export type OrderUpgrade = {
  id: string;
  userBID: string;
  legacyOrderIdentifier: string;
  legacyOrderId: number;
  legacyOrderItemId: number;
  sku: string;
  orderId: string | null;
  isUpgraded: boolean;
  createdAt: string;
  updatedAt: string;
  status: string;
};

type Tax = {
  amount: string;
  cartId: number;
  id: number;
  taxCategory: string;
  taxName: string;
  type: string;
  value: string;
};

export type ShippingMethod = {
  code: string;
  description: string;
  displayName: string;

  createdAt?: string | null;
  deletedAt?: string | null;
  id?: number;
  isActive?: boolean;
  isDeleted?: boolean;
  isDisplay?: boolean;
  updatedAt?: string | null;
};

export type Store = {
  address: string;
  buildingInfo: string;
  city: String;
  countryId: number;
  createdAt: string | null;
  deletedAt: null;
  id: 1;
  isActive: true;
  isDeleted: false;
  name: string;
  pickupFee: string;
  state: string;
  updatedAt: string | null;
  zipCode: string | null;
  country: ICountryCity;
};
export class ICountryCity {
  id?: number;
  name: string;
  countryId: number;
  country: string;
  state: string;
  stateId: number;
  isActive?: boolean;
  isDeleted?: boolean;
  createdAt?: Date;
  updatedAt?: Date;
  deletedAt?: Date;
}
