-- Create database (optional)
-- CREATE DATABASE tech_services_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- USE tech_services_db;

CREATE TABLE IF NOT EXISTS users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  username VARCHAR(50) UNIQUE NOT NULL,
  password_hash VARCHAR(255) NOT NULL,
  role ENUM('admin','agent') NOT NULL DEFAULT 'admin',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS services (
  id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(120) NOT NULL,
  category VARCHAR(60) NOT NULL,
  description TEXT NOT NULL,
  price_from DECIMAL(10,2) DEFAULT 0,
  is_active TINYINT(1) NOT NULL DEFAULT 1,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS inquiries (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(120) NOT NULL,
  email VARCHAR(150) NOT NULL,
  phone VARCHAR(40) NULL,
  service_id INT NULL,
  message TEXT NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Sample services
INSERT INTO services (title, category, description, price_from) VALUES
('Mantenimiento Preventivo de PC', 'Hardware', 'Limpieza interna, cambio de pasta térmica, optimización del sistema.', 25.00),
('Formateo e Instalación de Windows', 'Software', 'Respaldo de datos, instalación de Windows y drivers, suite básica.', 30.00),
('Instalación de Redes (LAN/Wi‑Fi)', 'Redes', 'Planificación, cableado estructurado, configuración de routers y switches.', 50.00),
('Armado de PC a Medida', 'Hardware', 'Asesoría de componentes, ensamblaje, pruebas de estrés y garantía.', 40.00);
