-- Schema manual (alternativa às migrations)
CREATE DATABASE IF NOT EXISTS vistoria CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
USE vistoria;

CREATE TABLE IF NOT EXISTS users (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(150) NOT NULL,
    email VARCHAR(191) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    role ENUM('admin', 'user') NOT NULL DEFAULT 'user',
    active TINYINT(1) NOT NULL DEFAULT 1,
    created_at DATETIME NULL,
    updated_at DATETIME NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS inspections (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id INT UNSIGNED NOT NULL,
    client_name VARCHAR(150) NOT NULL,
    requester_document VARCHAR(30) NULL,
    vehicle VARCHAR(150) NOT NULL,
    plate VARCHAR(20) NOT NULL,
    renavam VARCHAR(30) NULL,
    exercise_year VARCHAR(10) NULL,
    chassis VARCHAR(50) NULL,
    species_type VARCHAR(80) NULL,
    city_uf VARCHAR(120) NULL,
    manufacture_model_year VARCHAR(20) NULL,
    power_displacement VARCHAR(80) NULL,
    bodywork VARCHAR(80) NULL,
    cmt VARCHAR(30) NULL,
    pbt VARCHAR(30) NULL,
    axles VARCHAR(20) NULL,
    capacity VARCHAR(50) NULL,
    engine_number VARCHAR(50) NULL,
    fuel VARCHAR(50) NULL,
    color VARCHAR(50) NULL,
    category VARCHAR(50) NULL,
    front_photo_url TEXT NULL,
    rear_photo_url TEXT NULL,
    vehicle_video_url TEXT NULL,
    status ENUM('Em aberto', 'Aguardando', 'Aprovada', 'Reprovado') NOT NULL DEFAULT 'Em aberto',
    public_report_token VARCHAR(96) NULL UNIQUE,
    created_at DATETIME NULL,
    updated_at DATETIME NULL,
    CONSTRAINT fk_inspections_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE,
    INDEX idx_inspections_user (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Crie o usuário admin com: php spark db:seed AdminUserSeeder
-- Credenciais: admin@vistoria.local / admin123
