import type { ErrorLevel } from "@/components/product-import";

/**
 * Base field configuration for product import
 *
 * These fields define the structure and validation rules for the import process.
 * Options for select/multi-select fields are populated dynamically from the API.
 */
export const BASE_IMPORT_FIELDS = [
  {
    label: "Supplier",
    key: "supplier",
    description: "Primary supplier/manufacturer of the product",
    fieldType: {
      type: "select" as const,
      options: [], // Will be populated from API
    },
    width: 220,
    validations: [{ rule: "required" as const, errorMessage: "Required", level: "error" as ErrorLevel }],
  },
  {
    label: "Company",
    key: "company",
    description: "Company/Brand name",
    fieldType: {
      type: "select",
      options: [], // Will be populated from API
    },
    width: 220,
    validations: [{ rule: "required", errorMessage: "Required", level: "error" }],
  },
  {
    label: "Line",
    key: "line",
    description: "Product line",
    alternateMatches: ["collection"],
    fieldType: {
      type: "select" as const,
      options: [], // Will be populated dynamically based on company selection
    },
    width: 220,
    validations: [{ rule: "required", errorMessage: "Required", level: "error" }],
  },
  {
    label: "Sub Line",
    key: "subline",
    description: "Product sub-line",
    fieldType: {
      type: "select" as const,
      options: [], // Will be populated dynamically based on line selection
    },
    width: 220,
  },
  {
    label: "UPC",
    key: "upc",
    description: "Universal Product Code/Barcode",
    alternateMatches: ["barcode", "bar code", "jan", "ean", "upc code", "upc number"],
    fieldType: { type: "input" },
    width: 165,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "unique", errorMessage: "Must be unique", level: "error" },
      { rule: "regex", value: "^[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Item Number",
    key: "item_number",
    description: "Internal item reference number",
    fieldType: { type: "input" },
    width: 130,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "unique", errorMessage: "Must be unique", level: "error" },
    ],
  },
  {
    label: "Supplier #",
    key: "supplier_no",
    description: "Supplier's product identifier",
    alternateMatches: ["sku", "item#", "mfg item #", "item", "supplier #"],
    fieldType: { type: "input" },
    width: 130,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "unique", errorMessage: "Must be unique", level: "error" },
    ],
  },
  {
    label: "Notions #",
    key: "notions_no",
    description: "Internal notions number",
    alternateMatches: ["notions #","nmc"],
    fieldType: { type: "input" },
    width: 110,
    validations: [
      { rule: "unique", errorMessage: "Must be unique", level: "error" },
      { rule: "regex", value: "^[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Name",
    key: "name",
    description: "Product name/title",
    alternateMatches: ["sku description","product name","online name"],
    fieldType: { type: "input" },
    width: 400,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "unique", errorMessage: "Must be unique", level: "error" },
    ],
  },
  {
    label: "MSRP",
    key: "msrp",
    description: "Manufacturer's Suggested Retail Price",
    alternateMatches: ["retail", "retail price", "sugg retail", "price", "sugg. retail","default price","sugg. retail (indv. pack)"],
    fieldType: {
      type: "input",
      price: true
    },
    width: 110,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "regex", value: "^[0-9]*.?[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Min Qty",
    key: "qty_per_unit",
    description: "Quantity of items per individual unit",
    alternateMatches: ["inner pack", "inner", "min qty", "unit qty", "min. order qty", "supplier qty/unit", "wholesale pkg qty"],
    fieldType: { type: "input" },
    width: 100,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "regex", value: "^[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Cost Each",
    key: "cost_each",
    description: "Wholesale cost per unit",
    alternateMatches: ["wholesale", "wholesale price", "supplier cost each", "cost each","whls","wholesale cost"],
    fieldType: {
      type: "input",
      price: true
    },
    width: 120,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "regex", value: "^[0-9]*.?[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Case Pack",
    key: "case_qty",
    description: "Number of units per case",
    alternateMatches: ["mc qty","case qty","case pack","box ct","master"],
    fieldType: { type: "input" },
    width: 100,
    validations: [
      { rule: "regex", value: "^[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Tax Category",
    key: "tax_cat",
    description: "Product tax category",
    fieldType: {
      type: "select",
      options: [], // Will be populated from API
    },
    width: 200,
    validations: [{ rule: "required", errorMessage: "Required", level: "error" }],
  },
  {
    label: "Artist",
    key: "artist",
    description: "Artist/Designer name",
    fieldType: {
      type: "select",
      options: [], // Will be populated from API
    },
    width: 200,
  },
  {
    label: "ETA Date",
    key: "eta",
    description: "Estimated arrival date",
    alternateMatches: ["shipping month"],
    fieldType: { type: "input" },
    width: 120,
  },
  {
    label: "Length",
    key: "length",
    description: "Product length (in inches)",
    fieldType: { type: "input" },
    width: 100,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "regex", value: "^[0-9]*.?[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Width",
    key: "width",
    description: "Product width (in inches)",
    fieldType: { type: "input" },
    width: 100,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "regex", value: "^[0-9]*.?[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Height",
    key: "height",
    description: "Product height (in inches)",
    fieldType: { type: "input" },
    width: 100,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "regex", value: "^[0-9]*.?[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Weight",
    key: "weight",
    description: "Product weight (in oz — convert lbs ×16, kg ×35.274)",
    alternateMatches: ["weight (lbs.)", "weight (oz)", "weight (oz.)"],
    fieldType: { type: "input" },
    width: 100,
    validations: [
      { rule: "required", errorMessage: "Required", level: "error" },
      { rule: "regex", value: "^[0-9]*.?[0-9]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Shipping Restrictions",
    key: "ship_restrictions",
    description: "Product shipping restrictions",
    fieldType: {
      type: "select",
      options: [], // Will be populated from API
    },
    width: 190,
    validations: [{ rule: "required", errorMessage: "Required", level: "error" }],
  },
  { 
    label: "COO",
    key: "coo",
    description: "2-letter country code (ISO)",
    alternateMatches: ["coo", "country of origin", "origin"],
    fieldType: { type: "input" },
    width: 70,
    validations: [
      { rule: "regex", value: "^[A-Z]{2}$", errorMessage: "Must be 2 letters", level: "error" },
    ],
  },
  {
    label: "HTS Code",
    key: "hts_code",
    description: "Harmonized Tariff Schedule code",
    alternateMatches: ["taric","hts","hs code","hs code (commodity code)"],
    fieldType: { type: "input" },
    width: 130,
    validations: [
      { rule: "regex", value: "^[0-9.]+$", errorMessage: "Must be a number", level: "error" },
    ],
  },
  {
    label: "Size Category",
    key: "size_cat",
    description: "Product size category",
    fieldType: {
      type: "select",
      options: [], // Will be populated from API
    },
    width: 180,
  },
  {
    label: "Description",
    key: "description",
    description: "Detailed product description",
    alternateMatches: ["details/description","description of item"],
    fieldType: {
      type: "input",
      multiline: true
    },
    width: 500,
    validations: [{ rule: "required", errorMessage: "Required", level: "error" }],
  },
  {
    label: "Categories",
    key: "categories",
    description: "Product categories",
    fieldType: {
      type: "multi-select",
      options: [], // Will be populated from API
    },
    width: 400,
    validations: [{ rule: "required", errorMessage: "Required", level: "error" }],
  },
  {
    label: "Themes",
    key: "themes",
    description: "Product themes/styles",
    alternateMatches: ["themes"],
    fieldType: {
      type: "multi-select",
      options: [], // Will be populated from API
    },
    width: 300,
  },
  {
    label: "Colors",
    key: "colors",
    description: "Product colors",
    fieldType: {
      type: "multi-select",
      options: [], // Will be populated from API
    },
    width: 200,
  },
  {
    label: "Private Notes",
    key: "priv_notes",
    description: "Internal notes about the product",
    fieldType: {
      type: "input",
      multiline: true
    },
    width: 300,
  },
] as const;

export type ImportFieldKey = (typeof BASE_IMPORT_FIELDS)[number]["key"];