-- drop tables here
DROP TABLE IF EXISTS Account;
DROP TABLE IF EXISTS Tactic;
DROP TABLE IF EXISTS Team;
DROP TABLE IF EXISTS User;
DROP TABLE IF EXISTS Member;
CREATE TABLE Account
(
    id       integer PRIMARY KEY AUTOINCREMENT,
    email    varchar UNIQUE NOT NULL,
    username varchar        NOT NULL,
    token    varchar UNIQUE NOT NULL,
    hash     varchar        NOT NULL,
    profilePicture varchar  NOT NULL
);

CREATE TABLE Tactic
(
    id            integer PRIMARY KEY AUTOINCREMENT,
    name          varchar                             NOT NULL,
    creation_date timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
    owner         integer                             NOT NULL,
    content       varchar   DEFAULT '{"players": [], "actions": [], "objects": []}' NOT NULL,
    court_type    varchar CHECK ( court_type IN ('HALF', 'PLAIN')) NOT NULL,
    FOREIGN KEY (owner) REFERENCES Account
);

CREATE TABLE FormEntries
(
    name        varchar NOT NULL,
    description varchar NOT NULL
);


CREATE TABLE Team
(
    id           integer PRIMARY KEY AUTOINCREMENT NOT NULL,
    name         varchar                           NOT NULL,
    picture      varchar                           NOT NULL,
    main_color   varchar                           NOT NULL,
    second_color varchar                           NOT NULL
);


CREATE TABLE Member
(
    id_team integer                                     NOT NULL,
    id_user integer                                     NOT NULL,
    role    text CHECK (role IN ('COACH', 'PLAYER')) NOT NULL,
    FOREIGN KEY (id_team) REFERENCES Team (id),
    FOREIGN KEY (id_user) REFERENCES Account (id)
);
