CREATE_TABLE_APPARAT = """CREATE TABLE semesterapparat (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    name TEXT,
    prof_id INTEGER,
    fach TEXT,
    appnr INTEGER,
    erstellsemester TEXT,
    verlängert_am TEXT,
    dauer BOOLEAN,
    verlängerung_bis TEXT,
    deletion_status INTEGER,
    deleted_date TEXT,
    apparat_id_adis INTEGER,
    prof_id_adis INTEGER,
    konto INTEGER REFERENCES app_kontos (id),
    FOREIGN KEY (prof_id) REFERENCES prof (id)
  )"""
CREATE_TABLE_MEDIA = """CREATE TABLE media (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    bookdata BLOB,
    app_id INTEGER,
    prof_id INTEGER,
    deleted INTEGER DEFAULT (0),
    available BOOLEAN,
    reservation BOOLEAN,
    FOREIGN KEY (prof_id) REFERENCES prof (id),
    FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
  )"""
CREATE_TABLE_APPKONTOS = """CREATE TABLE app_kontos (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    app_id INTEGER,
    konto INTEGER,
    passwort TEXT,
    FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
    )"""
CREATE_TABLE_FILES = """CREATE TABLE files (
    id INTEGER PRIMARY KEY,
    filename TEXT,
    fileblob BLOB,
    app_id INTEGER,
    filetyp TEXT,
    prof_id INTEGER REFERENCES prof (id),
    FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
    )"""
CREATE_TABLE_MESSAGES = """CREATE TABLE messages (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    created_at date NOT NULL DEFAULT CURRENT_TIMESTAMP,
    message TEXT NOT NULL,
    remind_at date NOT NULL DEFAULT CURRENT_TIMESTAMP,
    user_id INTEGER NOT NULL,
    appnr INTEGER,
    FOREIGN KEY (user_id) REFERENCES user (id)
  )"""
CREATE_TABLE_PROF = """CREATE TABLE prof (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    titel TEXT,
    fname TEXT,
    lname TEXT,
    fullname TEXT NOT NULL UNIQUE,
    mail TEXT,
    telnr TEXT
  )"""
CREATE_TABLE_USER = """CREATE TABLE user (
    id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
    created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    username TEXT NOT NULL UNIQUE,
    password TEXT NOT NULL,
    salt TEXT NOT NULL,
    role TEXT NOT NULL,
    email TEXT UNIQUE,
    name TEXT
  )"""
CREATE_TABLE_SUBJECTS = """CREATE TABLE subjects (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    name TEXT NOT NULL UNIQUE
)"""

CREATE_ELSA_TABLE = """CREATE TABLE elsa (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    date TEXT NOT NULL,
    semester TEXT NOT NULL,
    prof_id INTEGER NOT NULL
  )"""
CREATE_ELSA_FILES_TABLE = """CREATE TABLE elsa_files (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    filename TEXT NOT NULL,
    fileblob BLOB NOT NULL,
    elsa_id INTEGER NOT NULL,
    filetyp TEXT NOT NULL,
    FOREIGN KEY (elsa_id) REFERENCES elsa (id)
  )"""
CREATE_ELSA_MEDIA_TABLE = """CREATE TABLE elsa_media (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    work_author TEXT,
    section_author TEXT,
    year TEXT,
    edition TEXT,
    work_title TEXT,
    chapter_title TEXT,
    location TEXT,
    publisher TEXT,
    signature TEXT,
    issue TEXT,
    pages TEXT,
    isbn TEXT,
    type TEXT,
    elsa_id INTEGER NOT NULL,
    FOREIGN KEY (elsa_id) REFERENCES elsa (id)
  )"""
