import type { productStatusValues } from "../db/schema.js";

export type ProductStatus = (typeof productStatusValues)[number];

export type ProductSort =
  | "newest"
  | "oldest"
  | "price_asc"
  | "price_desc"
  | "rating_desc"
  | "popular"
  | "name_asc";

export type ProductLookup = {
  id: number;
  name: string;
  slug: string;
};

export type ProductMedia = {
  id: number;
  url: string;
  altText: string | null;
  isPrimary: boolean;
  sortOrder: number;
};

export type ProductListItem = {
  id: number;
  sku: string;
  name: string;
  slug: string;
  description: string | null;
  basePrice: number;
  discountPercent: number;
  salePrice: number;
  stockQuantity: number;
  status: ProductStatus;
  isFeatured: boolean;
  averageRating: string;
  ratingCount: number;
  brand: ProductLookup | null;
  productType: ProductLookup | null;
  collection: ProductLookup | null;
  frameShape: ProductLookup | null;
  frameColor: (ProductLookup & { hexCode: string | null }) | null;
  ageGroup: ProductLookup | null;
  size: ProductLookup | null;
  primaryMedia: ProductMedia | null;
  media: ProductMedia[];
  createdAt: Date;
  updatedAt: Date;
};

export type ProductDetail = ProductListItem & {
  media: ProductMedia[];
  genders: ProductLookup[];
  faceShapes: ProductLookup[];
  lensFeatures: ProductLookup[];
  occasions: ProductLookup[];
};

export type PaginationMeta = {
  page: number;
  perPage: number;
  total: number;
  totalPages: number;
  hasNextPage: boolean;
  hasPreviousPage: boolean;
};

export type PaginatedProducts = {
  items: ProductListItem[];
  pagination: PaginationMeta;
};

export type FrameShapeWithMedia = ProductLookup & {
  media: ProductMedia[];
};

export type BrandWithMedia = ProductLookup & {
  media: ProductMedia[];
};

export type ProductTypeWithMedia = ProductLookup & {
  media: ProductMedia[];
};

export type ProductFiltersResponse = {
  brands: BrandWithMedia[];
  productTypes: ProductTypeWithMedia[];
  collections: ProductLookup[];
  occasions: ProductLookup[];
  frameShapes: FrameShapeWithMedia[];
  faceShapes: ProductLookup[];
  genders: ProductLookup[];
  frameColors: Array<ProductLookup & { hexCode: string | null }>;
  lensFeatures: ProductLookup[];
  ageGroups: Array<ProductLookup & { minAge: number | null; maxAge: number | null }>;
  sizes: ProductLookup[];
  priceRanges: Array<ProductLookup & { minPrice: number; maxPrice: number | null }>;
  sortOptions: Array<{ value: ProductSort; label: string }>;
};
