// تایپ‌های مربوط به سفارشات

export type OrderType = {
  _id: string;
  orderNumber: string;
  customer: {
    name: string;
  };
  seller?: {
    name: string;
  };
  amount: number;
  status: "Completed" | "Cancelled" | "Pending" | string;
  date: string;
  cancellationReason?: string;
  cancelledDate?: string;
};

export type PaymentType = {
  _id: string;
  transaction_id: string | null;
  payment_method: PaymentMethodType;
  priceDetails: PriceDetailsType;
  totalPrice: number;
  paymentStatus: string;
  createdAt: string;
};

export type PaymentMethodType = {
  _id: string;
  title_fa: string;
  title_en: string;
  description: string;
  provider: string;
  isActive: boolean;
  type: string;
};

export type PriceDetailsType = {
  shipping_cost: number;
  process_cost: number;
  total_retail_price: number;
  total_payable_price: number;
  total_discount: number;
  coupon_discount: number;
};

export type OrderItemsType = {
  _id: string;
  order_id: number;
  shop: ShopType;
  shipmentItems: ShipmentItemType[];
  shipper: ShipperType;
  trackCode: string | null;
  itemsCount: number;
  totalPaymentPrice: number;
  totalRetailPrice: number;
  totalSellingPrice: number;
  totalShipmentCost: number;
  postingDate: string | null;
  postingReceipt: string | null;
  status: string;
};

export type ShipmentItemType = {
  _id: string;
  product: ProductType;
  variant: VariantType;
  quantity: number;
  cancelled_quantity: number;
  returned_quantity: number;
  selling_price: number;
  retail_price: number;
  discount_percent: number;
  shipmentCost: number;
};

export type ProductType = {
  _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: ImagesUrlType;
  isFake: string;
  voice: string | null;
  specifications: SpecificationType[];
  brand: BrandType;
  category: CategoryType;
  variants: { _id: string }[];
};

export type ImagesUrlType = {
  cover: string;
  list: string[];
};

export type SpecificationType = {
  title: string;
  values: string[];
};

export type BrandType = {
  _id: string;
};

export type CategoryType = {
  _id: string;
};

export type WarrantyType = {
  _id: number;
  duration: string;
  logoUrl: string;
  name: string;
};

export type MeterageType = {
  _id: number;
  value: string;
};

export type VariantType = {
  _id: string;
  market_status: string;
  price: PriceType;
  stock: number;
  postingTime: number;
  isFreeShip: boolean;
  isWholeSale: boolean;
  shop: ShopType;
  warranty: WarrantyType;
  meterage: MeterageType;
};

export type PriceType = {
  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;
};

export type SaleFormatType = {
  wholeSale: unknown[];
};

export type ShopType = {
  _id: string;
  shopName?: string;
  shopCode?: number;
  owner?: string;
  shopDescription?: string;
  telephoneNumber?: string;
  isChatActive?: boolean;
  shopPostalCode?: string;
  logo?: string;
};

export type ShipperType = {
  _id: number;
  name: string;
  description: string;
  deliveryTime: number;
  deliveryType: string;
};

export type ShipmentAddressType = {
  address: string;
  city: string;
  province: string;
  plaque: string;
  postalCode: string;
  phone: string;
};

export type CancellationCategoryType = {
  _id: string;
  title: string;
  description: string;
  status: string;
  deleted: boolean;
};

export type ReturnCategoryType = {
  _id: string;
  title: string;
  description: string;
  status: string;
  deleted: boolean;
  fineRule?: FineRuleType;
  createdAt?: string;
  updatedAt?: string;
};

// تایپ‌های صفحه‌بندی
export type PagerType = {
  page: number;
  limit: number;
  totalItems: number;
  totalPages: number;
  prevPage: boolean | null;
  nextPage: boolean | null;
};

export type OrdersResponseType = {
  status: number;
  success: boolean;
  results: {
    orders: OrderType[];
    pager: PagerType;
  };
};

export type CategoriesResponseType = {
  status: number;
  success: boolean;
  results: {
    categories: CancellationCategoryType[] | ReturnCategoryType[];
    pager: PagerType;
  };
};

export type CreateCategoryType = {
  title: string;
  description: string;
};

// تایپ‌های مربوط به سفارشات بومی
export type PriceRangeType = {
  minPrice: number;
  maxPrice: number;
};

export type UserType = {
  fullName: string;
};

export type NativeOrderType = {
  _id: number;
  user: UserType;
  payment: PaymentType;
  orderItems: OrderItemsType;
  shipmentAddress: ShipmentAddressType;
  orderStatus: string;
  createdAt: string;
};

export type NativeOrdersResponseType = {
  status: number;
  success: boolean;
  results: {
    pager: PagerType;
    orders: NativeOrderType[];
    priceRange: PriceRangeType;
  };
};

// تایپ‌های مربوط به جزئیات سفارش
export type OrderDetailType = {
  _id: number;
  user: UserType;
  payment: PaymentType;
  orderItems: OrderItemsType[];
  shipmentAddress: ShipmentAddressType;
  orderStatus: string;
  createdAt: string;
};

export type OrderDetailResponseType = {
  status: number;
  success: boolean;
  results: {
    order: OrderDetailType;
  };
};

export type CreateCancelReasonType = {
  fineRule: string;
  title: string;
};

export type FineRuleType = {
  _id: string;
  title: string;
  fine_percentage: number;
  deleted: boolean;
  createdAt: string;
  updatedAt: string;
};

export type CancelReasonType = {
  _id: string;
  title: string;
  deleted: boolean;
  fineRule?: FineRuleType;
  createdAt?: string;
  updatedAt?: string;
};

export type CancelReasonsResponseType = {
  status: number;
  success: boolean;
  results: {
    reasons: CancelReasonType[];
  };
};

export type ReturnReasonType = {
  _id: string;
  title: string;
  is_mandatory_picture: boolean;
  fineRule?: FineRuleType | string;
  createdAt: string;
  updatedAt: string;
};

export type ReturnReasonsResponseType = {
  status: number;
  success: boolean;
  results: {
    reasons: ReturnReasonType[];
  };
};

export type CreateReturnReasonType = {
  title: string;
  is_mandatory_picture: boolean;
  fineRule: string;
};

// تایپ‌های مربوط به جزئیات مرجوعی
export type ReturnOrderDetailShipmentItemType = {
  _id: string;
  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;
};

export type ReturnOrderDetailOrderItemType = {
  _id: string;
  order: number;
  shop: string;
  shipmentItems: ReturnOrderDetailShipmentItemType[];
  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;
  createdAt: string;
  updatedAt: string;
  __v: number;
};

export type ReturnOrderDetailProductType = {
  _id: number;
  title_fa: string;
  title_en: string;
  seoTitle: string;
  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: unknown[];
  createdAt: string;
  updatedAt: string;
  __v: number;
  imagesUrl: ImagesUrlType;
  rate: number;
};

export type ReturnOrderDetailReturnItemShipmentItemType = {
  _id: string;
  product: ReturnOrderDetailProductType;
  variant: string;
  quantity: number;
  cancelled_quantity: number;
  returned_quantity: number;
  selling_price: number;
  retail_price: number;
  discount_percent: number;
  shipmentCost: number;
  isFreeShip: boolean;
};

export type ReturnOrderDetailReturnItemType = {
  _id: string;
  returnOrderId: string;
  orderItem: ReturnOrderDetailOrderItemType;
  shipmentItem: ReturnOrderDetailReturnItemShipmentItemType;
  quantity: number;
  comment: string;
  imagesUrl?: string;
  reason: ReturnReasonType;
  status: string;
  createdAt: string;
  updatedAt: string;
  __v: number;
};

export type ReturnOrderDetailOrderType = {
  _id: number;
  user: string;
  payment: string;
  shipmentAddress: ShipmentAddressType;
  orderStatus: string;
  createdAt: string;
  updatedAt: string;
  __v: number;
};

export type ReturnOrderDetailType = {
  _id: string;
  order: ReturnOrderDetailOrderType;
  status: string;
  total_price: number;
  shopName: string;
  createdAt: string;
  updatedAt: string;
  returnOrderItems: ReturnOrderDetailReturnItemType[];
};

export type ReturnOrderDetailResponseType = {
  status: number;
  success: boolean;
  results: {
    returnOrder: ReturnOrderDetailType;
  };
};

// تایپ‌های مربوط به کنسلی‌ها
export type CancellerDetailsType = {
  _id: string;
  fullName: string;
  phoneNumber: string;
  dateOfBirth: string | null;
  address: string;
  nationalCode: string | null;
  homeNumber: string | null;
  createdAt: string;
  updatedAt: string;
  __v: number;
};

export type CancelOrderOrderType = {
  _id: number;
  user: string;
  payment: string;
  shipmentAddress: ShipmentAddressType;
  orderStatus: string;
  createdAt: string;
  updatedAt: string;
  __v: number;
};

export type CancelOrderItemOrderItemType = {
  _id: string;
  order: number;
  shop: string;
  shipmentItems: {
    product: {
      shop: ShopType;
    };
  };
  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;
  createdAt: string;
  updatedAt: string;
  __v: number;
};

export type CancelOrderItemShipmentItemType = {
  _id: string;
  product: ReturnOrderDetailProductType;
  variant: string;
  quantity: number;
  cancelled_quantity: number;
  returned_quantity: number;
  selling_price: number;
  retail_price: number;
  discount_percent: number;
  shipmentCost: number;
  isFreeShip: boolean;
};

export type CancelOrderItemType = {
  quantity: number;
  comment: string;
  reason: CancelReasonType;
  _id: string;
  cancelOrderId: string;
  orderItem: CancelOrderItemOrderItemType;
  shipmentItem: CancelOrderItemShipmentItemType;
  status: string;
  createdAt: string;
  updatedAt: string;
  __v: number;
};

export type CancelOrderType = {
  _id: string;
  order: CancelOrderOrderType;
  status: string;
  total_price: number;
  createdAt: string;
  updatedAt: string;
  cancelOrderItems: CancelOrderItemType;
  canceller: string;
  cancellerRef: string;
  cancellReceipt: string | null;
  cancellComment: string | null;
  cancellDate: string | null;
  __v: number;
  cancellerDetails: CancellerDetailsType;
};

export type CancelsResponseType = {
  status: number;
  success: boolean;
  results: {
    pager: PagerType;
    cancelsOrders: CancelOrderType[];
  };
};

export type CompleteCancelType = {
  refundDate: string;
  refundComment: string;
  refundReceipt: string;
};
