"""
VSR product catalog schema types.
Field names are camelCase GraphQL conventions mapping to snake_case
Snowflake / RDS columns documented in infra/sql/FIELD_MAPPING.txt.
"""
type DealInfo {
  """
  Deal programme name (from SONY_INTERNAL.PROD.DEALS)
  """
  name: String!
  """
  Discount percentage, e.g. 20 means 20% off bulkPrice
  """
  discountPct: Float!
  """
  ISO date string — day the deal expires
  """
  endsAt: String
  """
  Pre-computed effective price after discount. Server-authoritative.
  """
  effectivePrice: Float!
  """
  When true, loose-item surcharge is waived for quantities below bulk factor
  """
  waiveLooseBulk: Boolean!
  """
  When true, min-order surcharge is waived for this deal
  """
  waiveMinOrder: Boolean!
}

type StockStatus {
  """
  True if product is available to order
  """
  available: Boolean!
  """
  Quantity on hand at CDS warehouse
  """
  cdsQty: Int
  """
  VSR-allocated quantity
  """
  vsrQty: Int
}

type MerchandiseItem {
  """
  12-digit UPC of this sub-item (e.g. colour variant of a vinyl bundle)
  """
  upc: String!
  """
  Human-readable option label (e.g. "Blue Vinyl Edition")
  """
  optionValue: String!
  """
  Effective price for this sub-item (may differ from parent)
  """
  effectivePrice: Float!
}

type MerchandiseRollup {
  """
  Display label for the rollup group
  """
  title: String!
  """
  Individual selectable sub-items
  """
  items: [MerchandiseItem!]!
}

type Product {
  id: ID!
  artistName: String!
  title: String!
  """
  12-digit UPC barcode
  """
  upcCd: String!
  """
  Catalog number / alternate ID (e.g. label cat#)
  """
  alternateCatalogId: String
  """
  Human-readable format (e.g. "CD ALBUM", "12 INCH VINYL ALBUM")
  """
  configurationName: String!
  """
  Short format code (e.g. "CD", "LP", "DVD")
  """
  configurationCode: String
  """
  RED price code used for wholesale pricing display (e.g. "LP29", "CD12")
  """
  priceCode: String
  genreName: String
  labelName: String
  """
  YYYY-MM-DD street date
  """
  inStoreDt: String
  """
  Wholesale bulk price before any deal discount
  """
  bulkPrice: Float!
  """
  Units per carton. Loose surcharge applies to the remainder beyond whole
  cartons (quantity % bulkFactor), not to full cartons.
  """
  bulkFactor: Int!
  """
  True when loose (non-carton) units incur a $0.30 per-unit surcharge
  """
  looseChargeFlag: Boolean!
  """
  True when minimum order quantities apply ($0.50/unit surcharge)
  """
  minOrderFlag: Boolean!
  returnsAllowed: Boolean!
  isExclusive: Boolean!
  """
  Account security group code, NULL for unrestricted products
  """
  accountSecurityGroup: String
  """
  CDN URL to 128x128 album art thumbnail
  """
  thumbnailUrl: String
  mediaTypeCode: String
  stockStatus: StockStatus!
  """
  Non-null when an active deal applies to this product
  """
  dealInfo: DealInfo
  """
  Non-null for bundle/rollup products with variant sub-items
  """
  merchandiseRollup: MerchandiseRollup
  """
  Server-computed final price (dealInfo.effectivePrice when on deal, else bulkPrice)
  """
  effectivePrice: Float!
}

type ProductConnection {
  products: [Product!]!
  totalPages: Int!
  totalCount: Int!
  page: Int!
  pageSize: Int!
}

type Deal {
  dealId: ID!
  dealName: String!
  labelName: String
  discountPct: Float!
  effectiveDate: String!
  endDate: String!
  waiveLooseBulk: Boolean!
  waiveMinOrder: Boolean!
  productCount: Int!
}

extend type Query {
  """
  Browse product catalog with optional filters
  """
  products(
    """
    Primary nav name, e.g. "ALL PRODUCTS", "MUSIC", "VIDEO"
    """
    primaryNav: String
    """
    Secondary nav name, e.g. "New Releases", "On Deal", "Best Sellers", "Genre",
    "Configuration", "Exclusive"
    """
    secondaryNav: String
    """
    Genre name, configuration name, deal name, week date (YYYY-MM-DD), etc.
    """
    category: String
    """
    1-based page number
    """
    page: Int
    """
    Rows per page. Driven by the nav row's lines_per_webpage (client-supplied).
    """
    pageSize: Int
  ): ProductConnection!

  """
  Full-text product search (artist name / title / UPC)
  """
  searchProducts(query: String!, page: Int, pageSize: Int): ProductConnection!

  """
  Single product detail
  """
  product(id: ID!): Product

  """
  Products related by genre + configuration (used in ProductDetailPage)
  """
  relatedProducts(
    genreName: String!
    configurationName: String!
    excludeId: ID!
    limit: Int
  ): [Product!]!

  """
  All currently active deal programmes
  """
  deals: [Deal!]!
}
