export type DesignElement =
  | {
      id: string;
      type: 'text';
      x: number;
      y: number;
      rotation: number;
      text: string;
      fontFamily: string;
      fontSize: number;
      fill: string;
    }
  | {
      id: string;
      type: 'image';
      x: number;
      y: number;
      rotation: number;
      width: number;
      height: number;
      src: string; // base64 data URL
    };

export type PrintArea = {
  xPct: number;
  yPct: number;
  wPct: number;
  hPct: number;
};

export type ProductDTO = {
  id: string;
  slug: string;
  name: string;
  category: string; // matches a Category.slug — categories are admin-managed, not a fixed set
  description: string;
  basePrice: number;
  personalisedPrice: number | null; // higher price for made-to-order items; null = use basePrice
  colors: string[];
  colorPhotos: Record<string, string>;
  colorPhotosBack: Record<string, string>;
  sizes: string[];
  mockup: string;
  printArea: PrintArea;
  printAreaBack: PrintArea | null;
  printAreaWidthMm: number;
  printAreaHeightMm: number;
  referenceWidthCm: number | null;
  referenceHeightCm: number | null;
  imageUrl: string | null;
  imageUrlBack: string | null;
  photoRecolorable: boolean;
  showOnPersonalised: boolean;
  showOnProducts: boolean;
  createdAt: string;
  onSale: boolean;
  effectivePrice: number; // basePrice, or the sale price while a sale is active
  originalPrice: number | null; // set to basePrice when onSale, so the UI can show a strikethrough
};

export type CartItem = {
  cartItemId: string;
  productId: string;
  slug: string;
  name: string;
  mockup: string;
  color: string;
  size: string | null;
  quantity: number;
  unitPrice: number;
  designJson: { front: DesignElement[]; back: DesignElement[] };
  designPreviewUrl: string;
  designPreviewUrlBack: string | null;
  placementPreviewUrl: string | null;
  placementPreviewUrlBack: string | null;
  designWidthCm: number | null;
  designHeightCm: number | null;
};

export type ProofDTO = {
  id: string;
  productId: string;
  productName: string;
  productSlug: string;
  customerName: string | null;
  customerEmail: string;
  color: string;
  quantity: number;
  unitPrice: number;
  imageDataUrl: string;
  note: string | null;
  status: 'PENDING' | 'APPROVED';
  createdAt: string;
};

export type MessageDTO = {
  id: string;
  proofId: string;
  sender: 'ADMIN' | 'CUSTOMER';
  body: string;
  createdAt: string;
};

export type CustomerDTO = {
  id: string;
  email: string;
  name: string | null;
};
