/**
 * Public catalog page types — wave-11 leaf-C (public-catalog-page).
 * Used by: apps/zync-api (proxy endpoint), apps/zync-www (Astro page + React island).
 */

import type { TenantTier } from './enums'

export type CatalogSectionType =
  | 'hero' | 'text' | 'products' | 'pricing_table' | 'cta' | 'gallery'

export interface CatalogHeroSection {
  type: 'hero'
  title: string
  subtitle?: string
  backgroundImageR2Key?: string
}

export interface CatalogTextSection {
  type: 'text'
  heading?: string
  markdown: string
}

export interface CatalogProduct {
  name: string
  description?: string
  price?: string          // pre-formatted display string
  priceAmount?: number
  currency?: string       // ISO 4217
  imageR2Key?: string
}

export interface CatalogProductsSection {
  type: 'products'
  heading?: string
  products: CatalogProduct[]
}

export interface CatalogPricingTableSection {
  type: 'pricing_table'
  heading?: string
  tiers: { name: string; price?: string }[]
  rows: { feature: string; values: (boolean | string)[] }[]
}

export interface CatalogCtaSection {
  type: 'cta'
  heading: string
  subtext?: string
  buttonLabel: string
  buttonUrl?: string
}

export interface CatalogGallerySection {
  type: 'gallery'
  heading?: string
  imageR2Keys: string[]
}

export type CatalogSection =
  | CatalogHeroSection
  | CatalogTextSection
  | CatalogProductsSection
  | CatalogPricingTableSection
  | CatalogCtaSection
  | CatalogGallerySection
  | { type: string; [k: string]: unknown }   // forward-compat: unknown types skipped

export interface CatalogTemplateContent {
  sections: CatalogSection[]
}

export interface CatalogTenantBranding {
  tenantId: string
  tenantTier: TenantTier
  logoR2Key: string | null
  primaryColor: string | null
  tenantName: string
  customDomain: string | null
}

/** Minimal form config embedded in catalog response when share has a lead_form_id. */
export interface CatalogLeadFormConfig {
  /** Form slug — used in POST /api/forms/:slug/submit?tenant=<tenantId> */
  slug: string
  /** Field definitions (FieldConfig[] from lead-form-builder spec) */
  fields: unknown
}

export interface CatalogShareUtmParams {
  utmSource: string | null
  utmMedium: string | null
  utmCampaign: string | null
}

export interface CatalogPublicResponse {
  template: { content: CatalogTemplateContent }
  share: {
    id: string
    settings: { lead_form_id?: string | null }
    utmParams: CatalogShareUtmParams
  }
  tenantBranding: CatalogTenantBranding
  /** Present only when share.settings.lead_form_id is set and form is active. */
  leadForm?: CatalogLeadFormConfig | null
}
