CREATE TABLE IF NOT EXISTS trainings (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT NOT NULL,
    training_type TEXT NOT NULL,
    mode TEXT NOT NULL,
    start DATETIME NOT NULL,
    end DATETIME NOT NULL,
    status TEXT NOT NULL
);

CREATE TABLE IF NOT EXISTS trainers (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    email TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS training_trainers (
    training_id INTEGER NOT NULL,
    trainer_id INTEGER NOT NULL,
    FOREIGN KEY (training_id) REFERENCES trainings(id),
    FOREIGN KEY (trainer_id) REFERENCES trainers(id),
    PRIMARY KEY (training_id, trainer_id)
);

CREATE TABLE IF NOT EXISTS training_areas (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT UNIQUE NOT NULL
);

CREATE TABLE IF NOT EXISTS trainer_training_areas (
    trainer_id INTEGER,
    training_area_id INTEGER,
    PRIMARY KEY (trainer_id, training_area_id),
    FOREIGN KEY (trainer_id) REFERENCES trainers(id),
    FOREIGN KEY (training_area_id) REFERENCES training_areas(id)
);

CREATE TABLE IF NOT EXISTS training_training_areas (
    training_id INTEGER,
    training_area_id INTEGER,
    PRIMARY KEY (training_id, training_area_id),
    FOREIGN KEY (training_id) REFERENCES trainings(id),
    FOREIGN KEY (training_area_id) REFERENCES training_areas(id)
);

CREATE TABLE IF NOT EXISTS admins (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    email TEXT UNIQUE NOT NULL,
    password TEXT NOT NULL
);