-- Migration 001 : création de la table users
-- Exécuter : mysql -u <user> -p <database> < migrations/001_create_users_table.sql

CREATE TABLE IF NOT EXISTS `users` (
    `id`                INT UNSIGNED        NOT NULL AUTO_INCREMENT,
    `last_name`         VARCHAR(100)        NOT NULL,
    `first_name`        VARCHAR(100)        NOT NULL,
    `email`             VARCHAR(255)        NOT NULL,
    -- NULL si le compte est lié uniquement via OAuth (pas de mot de passe local)
    `password`          VARCHAR(255)        NULL,
    `role`              ENUM('dev','manager','operator') NOT NULL DEFAULT 'operator',
    `google_id`         VARCHAR(255)        NULL COMMENT 'Sub claim Google OAuth',
    `google_email`      VARCHAR(255)        NULL COMMENT 'Email du compte Google lié',
    `google_avatar_url` VARCHAR(512)        NULL,
    `is_active`         TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
    `email_verified_at` DATETIME            NULL,
    `last_login_at`     DATETIME            NULL,
    `created_at`        DATETIME            NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`        DATETIME            NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uq_users_email`     (`email`),
    UNIQUE KEY `uq_users_google_id` (`google_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


-- Seed : utilisateurs initiaux
-- Mot de passe temporaire : "mdp" — à changer immédiatement en production

INSERT INTO `users` (`last_name`, `first_name`, `email`, `password`, `role`, `is_active`, `email_verified_at`) VALUES
(
    'Chantraine',
    'Guillaume',
    'guillaume.chantraine@gmail.com',
    '$2y$10$JAx4sjfNDwkworzIifAVvuncPjDzre/YrsKS7FNJuDy0rkjRX4LqK',
    'dev',
    1,
    NOW()
),
(
    'Salini',
    'Laura',
    'contact.valtrebbia@gmail.com',
    '$2y$10$OQsokBoUKPl1PIvn3obSE.pyJdlvk.IZXLfS9jSOOKraP327HROmG',
    'manager',
    1,
    NOW()
);
