-- Tettevi Group runtime compatibility patch
-- Run this after schema.sql if your live database was created from an older build.

ALTER TABLE users
  ADD COLUMN IF NOT EXISTS email_verified_at TIMESTAMP NULL,
  ADD COLUMN IF NOT EXISTS last_login_at TIMESTAMP NULL,
  ADD COLUMN IF NOT EXISTS is_active TINYINT(1) DEFAULT 1,
  ADD COLUMN IF NOT EXISTS auth_provider ENUM('local','google') DEFAULT 'local',
  ADD COLUMN IF NOT EXISTS role ENUM('super_admin','admin','editor','user') DEFAULT 'user';

ALTER TABLE products
  ADD COLUMN IF NOT EXISTS is_active TINYINT(1) DEFAULT 1,
  ADD COLUMN IF NOT EXISTS is_featured TINYINT(1) DEFAULT 0,
  ADD COLUMN IF NOT EXISTS featured_image VARCHAR(500),
  ADD COLUMN IF NOT EXISTS sale_price DECIMAL(12,2) NULL;

ALTER TABLE orders
  ADD COLUMN IF NOT EXISTS order_number VARCHAR(30) NULL,
  ADD COLUMN IF NOT EXISTS subtotal DECIMAL(12,2) DEFAULT 0,
  ADD COLUMN IF NOT EXISTS discount DECIMAL(12,2) DEFAULT 0,
  ADD COLUMN IF NOT EXISTS shipping DECIMAL(12,2) DEFAULT 0,
  ADD COLUMN IF NOT EXISTS total DECIMAL(12,2) DEFAULT 0,
  ADD COLUMN IF NOT EXISTS currency VARCHAR(5) DEFAULT 'GHS',
  ADD COLUMN IF NOT EXISTS billing_name VARCHAR(200),
  ADD COLUMN IF NOT EXISTS billing_email VARCHAR(191),
  ADD COLUMN IF NOT EXISTS billing_phone VARCHAR(20),
  ADD COLUMN IF NOT EXISTS billing_address TEXT,
  ADD COLUMN IF NOT EXISTS billing_city VARCHAR(100),
  ADD COLUMN IF NOT EXISTS billing_country VARCHAR(100) DEFAULT 'Ghana';
