-- Furnify Re-Up feature migration
-- Use this if you already imported the older Furnify/Sofaria schema.

CREATE TABLE IF NOT EXISTS reup_requests (
  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,
  service_type VARCHAR(80) NOT NULL,
  condition_level VARCHAR(80) NOT NULL,
  issue_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,
  fabric_preference VARCHAR(180) NULL,
  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 review',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  INDEX idx_reup_created (created_at),
  INDEX idx_reup_status (status),
  INDEX idx_reup_customer (customer_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
