-- Création de la base de données
CREATE DATABASE IF NOT EXISTS pizzeria_it CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Utilisation de la base de données
USE pizzeria_it;

-- Création de la table users
CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    role ENUM('admin', 'chef', 'cook', 'waiter') NOT NULL,
    status ENUM('active', 'inactive') DEFAULT 'active',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO users (username, password, role, status) 
VALUES ('admin', '$2y$10$KbQi6nJESXwvMdN5RqZsruu/P1PnkkIzKjzwNlPRe7ghRuVJozr.u', 'admin', 'active');

-- Création de l'utilisateur SQL "pizzeria" avec le mot de passe "pizzeria"
CREATE USER 'pizzeria'@'localhost' IDENTIFIED BY 'pizzeria';

-- Accorder tous les privilèges sur la base de données "pizzeria_it" à l'utilisateur "pizzeria"
GRANT ALL PRIVILEGES ON pizzeria_it.* TO 'pizzeria'@'localhost';

-- Appliquer les changements
FLUSH PRIVILEGES;

CREATE TABLE os (
    id INT AUTO_INCREMENT PRIMARY KEY,
    operating_system VARCHAR(255) NOT NULL,
    version VARCHAR(50) NOT NULL,
    architecture VARCHAR(50) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO os (operating_system, version, architecture) 
VALUES ('debian', '12', 'amd64');

CREATE TABLE language (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL UNIQUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO language (name) VALUES ('bash');

CREATE TABLE clients (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    client_code CHAR(3) NOT NULL UNIQUE CHECK (client_code REGEXP '^[A-Z0-9]{3}$'),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);


INSERT INTO clients (name, client_code) VALUES ('Example Client', 'ABC');
