-- Furnify Custom Sofa Quote feature migration
-- Use this if you already imported an older Furnify schema.

CREATE TABLE IF NOT EXISTS custom_sofa_quotes (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  request_number VARCHAR(40) NOT NULL UNIQUE,
  customer_name VARCHAR(140) NOT NULL,
  customer_phone VARCHAR(40) NOT NULL,
  customer_email VARCHAR(180) NULL,
  customer_city VARCHAR(140) NOT NULL,
  customer_address VARCHAR(255) NULL,
  sofa_type VARCHAR(80) NOT NULL,
  design_style VARCHAR(80) NOT NULL,
  material_preference VARCHAR(80) NOT NULL,
  color_preference VARCHAR(140) NULL,
  firmness VARCHAR(80) NOT NULL,
  feature_json TEXT NULL,
  width_cm DECIMAL(8,2) NOT NULL DEFAULT 0,
  depth_cm DECIMAL(8,2) NOT NULL DEFAULT 0,
  height_cm DECIMAL(8,2) NOT NULL DEFAULT 0,
  seat_count INT UNSIGNED NOT NULL DEFAULT 1,
  chaise_side VARCHAR(80) NULL,
  budget_range VARCHAR(100) NULL,
  timeline VARCHAR(100) NULL,
  inspiration_photo_path VARCHAR(255) NULL,
  room_photo_path VARCHAR(255) NULL,
  message TEXT NULL,
  estimate_low DECIMAL(12,2) NOT NULL DEFAULT 0,
  estimate_high DECIMAL(12,2) NOT NULL DEFAULT 0,
  final_quote DECIMAL(12,2) NULL,
  admin_notes TEXT NULL,
  status VARCHAR(80) NOT NULL DEFAULT 'For design review',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  INDEX idx_custom_created (created_at),
  INDEX idx_custom_status (status),
  INDEX idx_custom_customer (customer_name),
  INDEX idx_custom_type (sofa_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
