// Backend classification constants (mirror of frontend)

const ITEM_TYPES = {
  PRODUCE: "produce",
  MEAT: "meat",
  DAIRY: "dairy",
  BAKERY: "bakery",
  FROZEN: "frozen",
  PANTRY: "pantry",
  BEVERAGE: "beverage",
  SNACK: "snack",
  HOUSEHOLD: "household",
  PERSONAL_CARE: "personal_care",
  OTHER: "other",
};

const ITEM_GROUPS = {
  [ITEM_TYPES.PRODUCE]: [
    "Fruits",
    "Vegetables",
    "Salad Mix",
    "Herbs",
    "Organic Produce",
  ],
  [ITEM_TYPES.MEAT]: [
    "Beef",
    "Pork",
    "Chicken",
    "Seafood",
    "Deli Meat",
    "Prepared Meat",
  ],
  [ITEM_TYPES.DAIRY]: [
    "Milk",
    "Cheese",
    "Yogurt",
    "Butter",
    "Eggs",
    "Cream",
  ],
  [ITEM_TYPES.BAKERY]: [
    "Bread",
    "Rolls",
    "Pastries",
    "Cakes",
    "Bagels",
    "Tortillas",
  ],
  [ITEM_TYPES.FROZEN]: [
    "Frozen Meals",
    "Ice Cream",
    "Frozen Vegetables",
    "Frozen Meat",
    "Pizza",
    "Desserts",
  ],
  [ITEM_TYPES.PANTRY]: [
    "Canned Goods",
    "Pasta",
    "Rice",
    "Cereal",
    "Condiments",
    "Spices",
    "Baking",
    "Oils",
  ],
  [ITEM_TYPES.BEVERAGE]: [
    "Water",
    "Soda",
    "Juice",
    "Coffee",
    "Tea",
    "Alcohol",
    "Sports Drinks",
  ],
  [ITEM_TYPES.SNACK]: [
    "Chips",
    "Crackers",
    "Nuts",
    "Candy",
    "Cookies",
    "Protein Bars",
  ],
  [ITEM_TYPES.HOUSEHOLD]: [
    "Cleaning Supplies",
    "Paper Products",
    "Laundry",
    "Kitchen Items",
    "Storage",
  ],
  [ITEM_TYPES.PERSONAL_CARE]: [
    "Bath & Body",
    "Hair Care",
    "Oral Care",
    "Skincare",
    "Health",
  ],
  [ITEM_TYPES.OTHER]: [
    "Miscellaneous",
  ],
};

// Store zones - path-oriented physical shopping areas
// Applicable to Costco, 99 Ranch, Stater Bros, and similar large grocery stores
const ZONES = {
  ENTRANCE: "Entrance & Seasonal",
  PRODUCE_SECTION: "Produce & Fresh Vegetables",
  MEAT_SEAFOOD: "Meat & Seafood Counter",
  DELI_PREPARED: "Deli & Prepared Foods",
  BAKERY_SECTION: "Bakery",
  DAIRY_SECTION: "Dairy & Refrigerated",
  FROZEN_FOODS: "Frozen Foods",
  DRY_GOODS_CENTER: "Center Aisles (Dry Goods)",
  BEVERAGES: "Beverages & Water",
  SNACKS_CANDY: "Snacks & Candy",
  HOUSEHOLD_CLEANING: "Household & Cleaning",
  HEALTH_BEAUTY: "Health & Beauty",
  CHECKOUT_AREA: "Checkout Area",
};

// Default zone mapping for each item type
// This determines where items are typically found in the store
const ITEM_TYPE_TO_ZONE = {
  [ITEM_TYPES.PRODUCE]: ZONES.PRODUCE_SECTION,
  [ITEM_TYPES.MEAT]: ZONES.MEAT_SEAFOOD,
  [ITEM_TYPES.DAIRY]: ZONES.DAIRY_SECTION,
  [ITEM_TYPES.BAKERY]: ZONES.BAKERY_SECTION,
  [ITEM_TYPES.FROZEN]: ZONES.FROZEN_FOODS,
  [ITEM_TYPES.PANTRY]: ZONES.DRY_GOODS_CENTER,
  [ITEM_TYPES.BEVERAGE]: ZONES.BEVERAGES,
  [ITEM_TYPES.SNACK]: ZONES.SNACKS_CANDY,
  [ITEM_TYPES.HOUSEHOLD]: ZONES.HOUSEHOLD_CLEANING,
  [ITEM_TYPES.PERSONAL_CARE]: ZONES.HEALTH_BEAUTY,
  [ITEM_TYPES.OTHER]: ZONES.DRY_GOODS_CENTER,
};

// Optimal walking flow through the store
// Represents a typical shopping path that minimizes backtracking
// Start with perimeter (fresh items), then move to center aisles, end at checkout
const ZONE_FLOW = [
  ZONES.ENTRANCE,
  ZONES.PRODUCE_SECTION,
  ZONES.MEAT_SEAFOOD,
  ZONES.DELI_PREPARED,
  ZONES.BAKERY_SECTION,
  ZONES.DAIRY_SECTION,
  ZONES.FROZEN_FOODS,
  ZONES.DRY_GOODS_CENTER,
  ZONES.BEVERAGES,
  ZONES.SNACKS_CANDY,
  ZONES.HOUSEHOLD_CLEANING,
  ZONES.HEALTH_BEAUTY,
  ZONES.CHECKOUT_AREA,
];

// Validation helpers
const isValidItemType = (type) => Object.values(ITEM_TYPES).includes(type);

const isValidItemGroup = (type, group) => {
  if (!isValidItemType(type)) return false;
  return ITEM_GROUPS[type]?.includes(group) || false;
};

const isValidZone = (zone) => Object.values(ZONES).includes(zone);

const getSuggestedZone = (itemType) => {
  return ITEM_TYPE_TO_ZONE[itemType] || null;
};

module.exports = {
  ITEM_TYPES,
  ITEM_GROUPS,
  ZONES,
  ITEM_TYPE_TO_ZONE,
  ZONE_FLOW,
  isValidItemType,
  isValidItemGroup,
  isValidZone,
  getSuggestedZone,
};
