// تایپ‌های مربوط به ایجاد محصول سه مرحله‌ای
import { ProductStatus } from "../enum/ProductEnum";

// مرحله اول: جزئیات محصول
export type CreateProductDetailRequestType = {
  category: string;
  brand: string;
  model: string;
  title_fa: string;
  title_en: string;
  seoTitle: string;
  source: string;
  isFake: boolean;
};

export type DraftProductType = {
  id: number;
  title_fa: string;
  title_en: string;
  model: string;
  nextStep: string;
};

export type CreateProductDetailResponseType = {
  status: number;
  success: boolean;
  results: {
    message: string;
    draftProduct: DraftProductType;
  };
};

// مرحله دوم: ویژگی‌ها و توضیحات
export type ProductAttributeType = {
  id: number;
  values: number[];
};

export type CreateProductAttributeRequestType = {
  productId: number;
  attributes: ProductAttributeType[];
  description: string;
  metaDescription: string;
  tags: string[];
  advantages: string[];
  disAdvantages: string[];
};

export type CreateProductAttributeResponseType = {
  status: number;
  success: boolean;
  results: {
    success: boolean;
  };
};

// مرحله سوم: ذخیره نهایی
export type SaveProductRequestType = {
  productId: number;
  imagesList: string[];
  coverImage: string;
};

export type SaveProductResponseType = {
  status: number;
  success: boolean;
  results: {
    success: boolean;
  };
};

// تایپ برند
export type BrandType = {
  _id: string;
  name: string;
  title_fa: string;
  title_en: string;
};

export type BrandsResponseType = {
  status: number;
  success: boolean;
  results: {
    data: BrandType[];
  };
};

// تایپ عمومی محصول
export type ProductType = {
  productId: number;
  category: string;
  brand: string;
  model: string;
  title_fa: string;
  title_en: string;
  seoTitle: string;
  source: string;
  isFake: boolean;
  attributes?: ProductAttributeType[];
  description?: string;
  metaDescription?: string;
  tags?: string[];
  advantages?: string[];
  disAdvantages?: string[];
  imagesList?: string[];
  coverImage?: string;
};

// تایپ‌های مربوط به لیست محصولات

export type PagerType = {
  page: number;
  limit: number;
  totalItems: number;
  totalPages: number;
  prevPage: boolean | null;
  nextPage: string | null;
};

export type ProductPriceType = {
  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 ProductVariantType = {
  _id: string;
  market_status: string;
  price: ProductPriceType;
  stock: number;
  postingTime: number;
  isFreeShip: boolean;
  isWholeSale: boolean;
  shop: {
    _id: string;
  };
  warranty: number;
  size?: number;
  meterage?: number;
};

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

export type ProductListType = {
  _id: number;
  title_fa: string;
  title_en: string;
  seoTitle: string | null;
  seoDescription: string | null;
  description: string;
  metaDescription: string;
  shopName: string;
  category_title_fa: string;
  category_id: string;
  brand_title_fa: string;
  status: ProductStatus;
  adminComments: string | null;
  step: number;
  isFake: boolean;
  imagesUrl: ProductImagesType;
  variantCount: number;
  default_variant: ProductVariantType;
  popular: boolean;
  incredible: boolean;
  voice: string | null;
};

export type BrandListType = {
  _id: string;
  status: string;
  title_en: string;
  title_fa: string;
  images: string[];
  logoUrl: string;
};

export type CategoryListType = {
  _id: string;
  title_fa: string;
};

export type GetProductsResponseType = {
  status: number;
  success: boolean;
  results: {
    pager: PagerType;
    products: ProductListType[];
    brands: BrandListType[];
    categories: CategoryListType[];
  };
};

// تایپ‌های مربوط به variant های محصول
export type ShipmentMethodType = {
  _id: number;
  name: string;
  description: string;
  deliveryTime: number;
  deliveryType: string;
};

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

export type ProductVariantDetailType = {
  _id: string;
  product_id: number;
  title_fa: string;
  title_en: string;
  model: string;
  market_status: string;
  productCode: string;
  category_title_fa: string;
  is_variant_active: boolean;
  coverImage: string;
  price: ProductPriceType;
  stock: number;
  sellerSpecialCode?: string;
  shipmentMethod: ShipmentMethodType[];
  product_status: string;
  isFreeShip: boolean;
  isWholeSale: boolean;
  size: SizeType;
};

export type GetProductVariantsResponseType = {
  status: number;
  success: boolean;
  results: {
    count: number;
    productVariants: ProductVariantDetailType[];
  };
};

export type GetVariantByIdResponseType = {
  status: number;
  success: boolean;
  results: {
    productVariant: ProductVariantDetailType;
  };
};

export type CreateProductVariantRequestType = {
  productId: string;
  colorId?: number;
  sizeId?: number;
  meterageId?: number;
  warrantyId: number;
  order_limit: number;
  sellerSpecialCode: string;
  retail_price: number;
  package_weight: number;
  package_height: number;
  package_length: number;
  package_width: number;
  postingTime: number;
  stock: number;
};

export type CreateProductVariantResponseType = {
  status: number;
  success: boolean;
  results: {
    variant: ProductVariantDetailType;
  };
};

// تایپ‌های مربوط به جزئیات محصول
export type ProductSpecificationType = {
  title: string;
  values: string[];
};

export type ProductCategoryType = {
  _id: string;
  title_fa: string;
  title_en: string;
  icon: string;
  imageUrl: string;
  description: string;
  variants: number[];
  hierarchy: string[];
  leaf: boolean;
  parent: string;
  deleted: boolean;
  createdAt: string;
  updatedAt: string;
  theme: string;
  url: string;
  children: ProductCategoryType[];
};

export type ProductBrandType = {
  _id: string;
  title_fa: string;
  title_en: string;
  category: string | null;
  status: string;
  description: string;
  logoUrl: string;
  images: string[];
  deleted: boolean;
  createdAt: string;
  updatedAt: string;
  url: string;
};

export type ProductDetailsType = {
  _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: ProductCategoryType;
  shop: string;
  brand: ProductBrandType;
  status: string;
  adminComments: string | null;
  step: number;
  isFake: boolean;
  variants: string[];
  voice: string | null;
  deleted: boolean;
  specifications: ProductSpecificationType[];
  createdAt: string;
  updatedAt: string;
  imagesUrl: ProductImagesType;
  url: string;
};

export type GetProductByIdResponseType = {
  status: number;
  success: boolean;
  results: {
    product: ProductDetailsType;
  };
};

// تایپ‌های مربوط به آپدیت variant
export type WholeSaleItemType = {
  from: number;
  to: number;
  price: number;
};

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

export type UpdateVariantRequestType = {
  productId: string;
  variantId: string;
  retailPrice: number;
  order_limit: number;
  sellerSpecialCode: string;
  stock: number;
  saleFormat: SaleFormatType;
  discount_type: "fixed" | "percent";
  discount_value?: number;
  discount_percent?: number;
  specialSale_order_limit: number;
  specialSale_quantity: number;
  specialSale_endDate: string;
};

export type UpdateVariantResponseType = {
  status: number;
  success: boolean;
  results: {
    variant: ProductVariantDetailType;
  };
};

// تایپ‌های مربوط به آپدیت محصول سه مرحله‌ای

// مرحله اول: آپدیت جزئیات محصول
export type UpdateProductDetailRequestType = {
  productId: number;
} & Omit<CreateProductDetailRequestType, "category" | "brand"> & {
    category?: string;
    brand?: string;
  };

export type UpdateProductDetailResponseType = {
  status: number;
  success: boolean;
  results: {
    message: string;
    product: DraftProductType;
  };
};

// مرحله دوم: آپدیت ویژگی‌ها و توضیحات
export type UpdateProductAttributeRequestType = {
  productId: number;
} & CreateProductAttributeRequestType;

export type UpdateProductAttributeResponseType = {
  status: number;
  success: boolean;
  results: {
    success: boolean;
  };
};

// مرحله سوم: آپدیت تصاویر و ذخیره نهایی
export type UpdateProductRequestType = {
  productId: number;
} & SaveProductRequestType;

export type UpdateProductResponseType = {
  status: number;
  success: boolean;
  results: {
    success: boolean;
  };
};
