/**
 * PDP (Product Detail Page) shared types.
 * Must stay in sync with Convex return shapes:
 * - products.getBySlug → ProductDetailProduct
 * - categories.getById → ProductDetailCategory (same as Doc<"categories">)
 * - reviews.listByProduct → { page, total, hasMore }
 */

/** Single review as returned by reviews.listByProduct (page item with userName). */
export type ProductDetailReview = {
  _id: string;
  productId: string;
  userId: string;
  rating: number;
  title: string;
  content: string;
  verifiedPurchase: boolean;
  helpfulCount: number;
  createdAt: number;
  updatedAt?: number;
  userName?: string;
};

/** Product image as returned by products.getBySlug (productImages by position). */
export type ProductDetailImage = {
  _id: string;
  productId: string;
  url: string;
  alt?: string;
  position: number;
};

/** Product variant (active only) as returned by products.getBySlug. */
export type ProductDetailVariant = {
  _id: string;
  productId: string;
  name: string;
  sku: string;
  price: number;
  compareAtPrice?: number;
  stockQuantity: number;
  attributes?: {
    size?: string;
    flavor?: string;
    color?: string;
  };
  isActive: boolean;
};

/** Category doc shape used for breadcrumb (and included on product). */
export type ProductDetailCategory = {
  _id: string;
  name: string;
  slug: string;
  description?: string;
  imageUrl?: string;
  parentId?: string;
  topCategorySlug?: string;
  seoTitle?: string;
  seoDescription?: string;
};

/** Product document fields (subset used on PDP). */
export type ProductDetailProductBase = {
  _id: string;
  name: string;
  slug: string;
  description?: string;
  shortDescription?: string;
  status: "active" | "draft" | "archived";
  categoryId: string;
  brand?: string;
  tags: string[];
  attributes?: {
    petSize?: string[];
    ageRange?: string[];
    specialDiet?: string[];
    material?: string;
    flavor?: string;
  };
  seoTitle?: string;
  seoDescription?: string;
  canonicalSlug?: string;
  averageRating?: number;
  reviewCount?: number;
  createdAt?: number;
  updatedAt?: number;
};

/**
 * PDP product: active product by slug with images (by position) and active variants.
 * Matches return type of Convex products.getBySlug.
 */
export type ProductDetailProduct = ProductDetailProductBase & {
  images: ProductDetailImage[];
  variants: ProductDetailVariant[];
  category: ProductDetailCategory | null;
};

/**
 * Breadcrumb segment for PDP.
 * Home → Shop → [Category] → [Subcategory] → Product (current, not linked).
 * Use with ShopBreadcrumbBar: last item has no href and gets aria-current="page".
 */
export type ProductDetailBreadcrumbItem = {
  label: string;
  href?: string;
};

/**
 * Sort options for the reviews list.
 */
export type ReviewSortOption = "newest" | "oldest" | "highest" | "lowest" | "helpful";
