-- admins
CREATE TABLE IF NOT EXISTS admin (
     id INT AUTO_INCREMENT PRIMARY KEY,
     username VARCHAR(255) NOT NULL,
     password VARCHAR(255) NOT NULL,
     permissions INT NOT NULL
);

-- user
CREATE TABLE IF NOT EXISTS user (
    id INT AUTO_INCREMENT PRIMARY KEY,
    firstname VARCHAR(255) NOT NULL,
    lastname VARCHAR(255) NOT NULL,
    birthday DATE NOT NULL,
    telephone VARCHAR(255),
    username VARCHAR(255) NOT NULL,
    edition ENUM('java', 'bedrock'),
    uuid VARCHAR(36)
);

-- blocked user
CREATE TABLE IF NOT EXISTS blocked_user (
    id INT AUTO_INCREMENT PRIMARY KEY,
    uuid VARCHAR(255) UNIQUE NOT NULL,
    comment TINYTEXT
);

-- direct signup
CREATE TABLE IF NOT EXISTS direct_signup (
    hash CHAR(255) NOT NULL UNIQUE,
    user_id INT,
    FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE
);

-- report
CREATE TABLE IF NOT EXISTS report (
    id INT AUTO_INCREMENT PRIMARY KEY,
    reason VARCHAR(255) NOT NULL,
    body TEXT,
    url_hash VARCHAR(255) NOT NULL UNIQUE,
    created_at TIMESTAMP,
    reporter_id INT,
    reported_id INT,
    FOREIGN KEY (reporter_id) REFERENCES user(id) ON DELETE CASCADE,
    FOREIGN KEY (reported_id) REFERENCES user(id) ON DELETE CASCADE
);

-- report attachment
CREATE TABLE IF NOT EXISTS report_attachment (
    id INT AUTO_INCREMENT PRIMARY KEY,
    type ENUM('image', 'video') NOT NULL,
    hash CHAR(32) NOT NULL,
    report_id INT NOT NULL,
    FOREIGN KEY (report_id) REFERENCES report(id) ON DELETE CASCADE
);

-- report status
CREATE TABLE IF NOT EXISTS report_status (
    status ENUM('open', 'closed'),
    notice TEXT,
    statement TEXT,
    report_id INT NOT NULL UNIQUE,
    reviewer_id INT,
    FOREIGN KEY (report_id) REFERENCES report(id) ON DELETE CASCADE,
    FOREIGN KEY (reviewer_id) REFERENCES admin(id) ON DELETE CASCADE
);

-- strike reason
CREATE TABLE IF NOT EXISTS strike_reason (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    weight TINYINT NOT NULL
);

-- strike
CREATE TABLE IF NOT EXISTS strike (
    at TIMESTAMP NOT NULL,
    report_id INT NOT NULL UNIQUE,
    strike_reason_id INT NOT NULL,
    FOREIGN KEY (report_id) REFERENCES report(id) ON DELETE CASCADE,
    FOREIGN KEY (strike_reason_id) REFERENCES strike_reason(id) ON DELETE CASCADE
);

-- feedback
CREATE TABLE IF NOT EXISTS feedback (
    id INT AUTO_INCREMENT PRIMARY KEY,
    event VARCHAR(255) NOT NULL,
    title VARCHAR(255),
    content TEXT,
    url_hash VARCHAR(255) NOT NULL UNIQUE,
    last_changed TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    user_id INT,
    FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE
);

-- settings
CREATE TABLE IF NOT EXISTS settings (
    name VARCHAR(255) UNIQUE NOT NULL,
    value TEXT NOT NULL
);
