-- 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
);

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": []}' NOT NULL,
    FOREIGN KEY (owner) REFERENCES Account
);

CREATE TABLE FormEntries
(
    name        varchar,
    description varchar
);


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


CREATE TABLE Member
(
    id_team integer,
    id_user integer,
    role    char(1) CHECK (role IN ('Coach', 'Player')),
    FOREIGN KEY (id_team) REFERENCES Team (id),
    FOREIGN KEY (id_user) REFERENCES User (id)
);
