// Cart Item Types
export type CartItemType = {
  product: {
    _id: number;
    title_fa: string;
    title_en: string;
    seoTitle: string | null;
    seoDescription: string | null;
    source: string;
    description: string;
    metaDescription: string;
    tags: string[];
    advantages: string[];
    disAdvantages: string[];
    imagesUrl: {
      cover: string;
      list: string[];
    };
    isFake: string;
    voice: string | null;
    specifications: Array<{
      title: string;
      values: string[];
    }>;
    category: {
      _id: string;
    };
  };
  variant: {
    _id: string;
    market_status: string;
    price: {
      order_limit: number;
      retailPrice: number;
      selling_price: number;
      is_specialSale: boolean;
      discount_percent: number;
      specialSale_order_limit: number | null;
      specialSale_quantity: number | null;
      specialSale_endDate: string | null;
    };
    stock: number;
    postingTime: number;
    isFreeShip: boolean;
    isWholeSale: boolean;
    shop: {
      _id: string;
      shopName: string;
      shopCode: number;
      owner: string;
      shopDescription: string;
      telephoneNumber: string;
      isChatActive: boolean;
      shopPostalCode: string;
      logo: string;
    };
    shipmentMethod: Array<{
      _id: number;
      name: string;
      description: string;
      deliveryTime: number;
      deliveryType: string;
    }>;
    warranty: {
      _id: number;
      duration: string;
      logoUrl: string;
      name: string;
    };
    meterage?: {
      _id: number;
      value: string;
    };
    size?: {
      _id: number;
      value: string;
    };
  };
  quantity: number;
};

// Cart Types
export type CartType = {
  _id: string;
  coupon_discount: number;
  items: CartItemType[];
  items_count: number;
  payable_price: number;
  retail_price: number;
  total_discount: number;
  user: {
    _id: string;
    fullName: string;
    phoneNumber: string;
    dateOfBirth: string | null;
    address: {
      _id: string;
    };
    nationalCode: string | null;
    homeNumber: string | null;
  };
  isWholeSale: boolean;
};

// Recommended Product Type
export type RecommendedProductType = {
  _id: number;
  title_fa: string;
  title_en: string;
  seoTitle: string | null;
  seoDescription: string | null;
  model: string;
  source: string;
  description: string;
  metaDescription: string;
  tags: string[];
  advantages: string[];
  disAdvantages: string[];
  totalRate: number;
  category: string;
  shop: string;
  brand: string;
  status: string;
  adminComments: string | null;
  step: number;
  isFake: boolean;
  variants: string[];
  voice: string | null;
  deleted: boolean;
  specifications: Array<{
    title: string;
    values: string[];
  }>;
  createdAt: string;
  updatedAt: string;
  imagesUrl: {
    cover: string;
    list: string[];
  };
  url: string;
};

// Cart API Response Type
export type CartResponseType = {
  status: number;
  success: boolean;
  results: {
    cart: CartType;
    recommended: RecommendedProductType[];
  };
};

// Cart Action Types
export type AddCartType = {
  productId: number;
  variantId: string;
};

export type UpdateCartType = {
  productId: number;
  variantId: string;
  quantity: number;
};

export type RemoveCartType = {
  productId: number;
  variantId: string;
};

export type BulkAddCartItemType = {
  productId: number;
  variantId: string;
  quantity: number;
};

export type BulkAddCartType = {
  items: BulkAddCartItemType[];
};

// Shipping Cost Types
export type ShippingItemType = {
  product: number;
  variant: string;
  quantity: number;
  selling_price: number;
  retail_price: number;
  discount_percent: number;
  shippingCost: number;
  isFreeShip: boolean;
};

export type ShipperType = {
  shipperId: number;
  shipperName: string;
  shippingDaysRange: string[];
  totalShippingCost: number;
  items: ShippingItemType[];
};

export type ShopShippingType = {
  shopId: string;
  shopName: string;
  items: Array<{
    product: {
      _id: number;
      url: string;
      title_fa: string;
      title_en: string;
      seoTitle: string | null;
      seoDescription: string | null;
      source: string;
      description: string;
      metaDescription: string;
      tags: string[];
      advantages: string[];
      disAdvantages: string[];
      imagesUrl: {
        cover: string;
        list: string[];
      };
      isFake: string;
      voice: string | null;
      specifications: Array<{
        title: string;
        values: string[];
      }>;
      brand: {
        _id: string;
      };
      category: {
        _id: string;
      };
      variants: Array<{
        _id: string;
      }>;
    };
    variant: {
      _id: string;
      market_status: string;
      price: {
        order_limit: number;
        retailPrice: number;
        selling_price: number;
        is_specialSale: boolean;
        discount_percent: number;
        specialSale_order_limit: number | null;
        specialSale_quantity: number | null;
        specialSale_endDate: string | null;
      };
      stock: number;
      postingTime: number;
      isFreeShip: boolean;
      isWholeSale: boolean;
      shop: {
        _id: string;
        shopName: string;
        shopCode: number;
        owner: string;
        shopDescription: string;
        telephoneNumber: string;
        isChatActive: boolean;
        shopPostalCode: string;
        logo: string;
      };
      warranty: {
        _id: number;
        duration: string;
        logoUrl: string;
        name: string;
      };
      meterage?: {
        _id: number;
        value: string;
      };
      size?: {
        _id: number;
        value: string;
      };
    };
    quantity: number;
  }>;
  shippers: ShipperType[];
};

// Shipping Cost API Response Type
export type ShippingCostResponseType = {
  status: number;
  success: boolean;
  results: {
    shipping: ShopShippingType[];
  };
};

// Payment Method Types
export type PaymentMethodType = {
  _id: string;
  title_fa: string;
  title_en: string;
  description: string;
  provider: string;
  isActive: boolean;
  type: string;
  createdAt: string;
  updatedAt: string;
};

// Payment Methods API Response Type
export type PaymentMethodsResponseType = {
  status: number;
  success: boolean;
  results: {
    paymentMethods: PaymentMethodType[];
  };
};

export type CheckoutCartType = {
  payment_method_id: string;
};

export type CheckoutResponseType = {
  status: number;
  success: boolean;
  results: {
    paymentData: {
      redirectUrl: string;
      message: string;
      authority: string;
    };
    order: {
      user: string;
      payment: string;
      shipmentAddress: {
        address: string;
        city: string;
        province: string;
        phone: string;
        plaque: string;
        postalCode: string;
        _id: string;
      };
      orderStatus: string;
      createdAt: string;
      updatedAt: string;
      _id: number;
    };
    orderItems: Array<{
      order: number;
      shop: string;
      shipmentItems: Array<{
        product: number;
        variant: string;
        quantity: number;
        cancelled_quantity: number;
        returned_quantity: number;
        selling_price: number;
        retail_price: number;
        discount_percent: number;
        shipmentCost: number;
        isFreeShip: boolean;
        _id: string;
      }>;
      shipper: number;
      totalSellingPrice: number;
      totalRetailPrice: number;
      totalShipmentCost: number;
      totalCouponDiscount: number;
      totalPaymentPrice: number;
      itemsCount: number;
      trackCode: string | null;
      postingDate: string | null;
      postingReceipt: string | null;
      status: string;
      _id: string;
      createdAt: string;
      updatedAt: string;
    }>;
  };
};

export type ApplyDiscountType = {
  discount_code: string;
};

export type ApplyDiscountResponseType = {
  status: number;
  success: boolean;
  results: {
    discount: {
      code: string;
      amount: number;
      type: string;
    };
  };
};

export type PaymentStatusType = {
  authority: string;
};

export type PaymentStatusResponseType = {
  status: number;
  success: boolean;
  results: {
    paymentStatus: "success" | "failed" | "pending";
    orderStatus: string;
    message: string;
    orderId?: number;
    orderData?: {
      orderId: number;
      totalPaymentPrice: number;
      createdAt: string;
      orderStatus: string;
    };
  };
};

// Shipment Save Types
export type ShipmentInfoType = {
  shopId: string;
  shipmentId: number;
};

export type ShipmentSaveType = {
  shipmentsInfo: ShipmentInfoType[];
};

// Shipment Cart Response Type
export type ShipmentCartResponseType = {
  status: number;
  success: boolean;
  results: {
    cart: CartType;
    recommended: RecommendedProductType[];
  };
};
