PRAGMA foreign_keys = ON;

CREATE TABLE [IF NOT EXISTS] [User].users (
	id INTEGER PRIMARY KEY,
   	name VARCHAR NOT NULL,
	username VARCHAR NOT NULL UNIQUE,
    email VARCHAR NOT NULL,
    password VARCHAR NOT NULL,
    dob TEXT,
    gender_type TEXT CHECK(gender_type IN ('trans','cis','nb')),
    gender_id TEXT CHECK(gender_id IN ('fem','masc','combined','fluid','none')),
    bio TEXT,
    affil TEXT,
    perms TEXT,
    user_token VARCHAR,
    pub_keys TEXT,
    totp_secret TEXT,
    ltotp TEXT,
    fido_priority INTEGER,
    fido_creds TEXT,
    fido_keys TEXT,
    fido_enabled INTEGER,
    fido_active INTEGER,
    totp_enabled INTEGER,
    totp_active INTEGER
) [WITHOUT ROWID];

INSERT INTO users (
    username,
    password,
    email,
    perms
) 
VALUES (
    'root',
    '$argon2id$v=19$m=256,t=1,p=4$JRuXmK5RvRJvvpvpWIF2UA$0uf3V1FHaIVmCgp2JfF+Mfrm66ihKXhKkf0RN820y/k',
    'admin@sukaato.moe',
    '[15, 15, 15, 15, 15, 15]'
);

CREATE TABLE [IF NOT EXISTS] [Post].posts (
	id INTEGER PRIMARY KEY,
   	title TEXT NOT NULL UNIQUE,
	abst TEXT,
    auth_id INTEGER,
    rev_id INTEGER,
    slug VARCHAR,
    content TEXT,
    tags TEXT,
    cat VARCHAR,
    ledit TEXT,
    FOREIGN KEY (auth_id)
    REFERENCES users (id),
    FOREIGN KEY (rev_id)
    REFERENCES users (id)
) [WITHOUT ROWID];

CREATE TABLE [IF NOT EXISTS] [Folio].folios (
	id INTEGER PRIMARY KEY,
   	user_id INTEGER NOT NULL,
    resume TEXT,
    showcase TEXT,
    theme_uri VARCHAR,
    FOREIGN KEY (user_id)
    REFERENCES users (id)
) [WITHOUT ROWID];

CREATE TABLE [IF NOT EXISTS] [Comment].comments (
    id INTEGER PRIMARY KEY,
    post_id INTEGER NOT NULL,
    reply_to INTEGER,
    slug VARCHAR,
    tripcode VARCHAR UNIQUE,
    content TEXT,
    ledit TEXT,
    FOREIGN KEY (post_id)
    REFERENCES posts (id),
    FOREIGN KEY (reply_to),
    REFERENCES comments (id)
) [WITHOUT ROWID];