CREATE TABLE teachers (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    introductory_video          VARCHAR(1024) NULL,
    years_teaching              SMALLINT NOT NULL DEFAULT 0,
    years_playing               SMALLINT NOT NULL DEFAULT 0,
    teaches_age_lower           SMALLINT NOT NULL DEFAULT 0,
    teaches_age_upper           SMALLINT NOT NULL DEFAULT 0,
    teaches_beginner            BOOLEAN NOT NULL DEFAULT FALSE,
    teaches_intermediate        BOOLEAN NOT NULL DEFAULT FALSE,
    teaches_advanced            BOOLEAN NOT NULL DEFAULT FALSE,
    website                     VARCHAR(1024) NULL,
    biography                   VARCHAR(4096) NULL,
    prices_per_lesson           BOOLEAN NOT NULL DEFAULT FALSE,
    prices_per_month            BOOLEAN NOT NULL DEFAULT FALSE,
    lesson_duration_30          BOOLEAN NOT NULL DEFAULT FALSE,
    lesson_duration_45          BOOLEAN NOT NULL DEFAULT FALSE,
    lesson_duration_60          BOOLEAN NOT NULL DEFAULT FALSE,
    lesson_duration_90          BOOLEAN NOT NULL DEFAULT FALSE,
    lesson_duration_120         BOOLEAN NOT NULL DEFAULT FALSE,
    price_per_lesson_30_cents   INT NULL,
    price_per_lesson_45_cents   INT NULL,
    price_per_lesson_60_cents   INT NULL,
    price_per_lesson_90_cents   INT NULL,
    price_per_lesson_120_cents  INT NULL,
    price_per_month_30_cents    INT NULL,
    price_per_month_45_cents    INT NULL,
    price_per_month_60_cents    INT NULL,
    price_per_month_90_cents    INT NULL,
    price_per_month_120_cents   INT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE users ADD COLUMN teacher_id VARCHAR(64) REFERENCES teachers(id) ON DELETE SET NULL;

CREATE TABLE subjects(
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    description VARCHAR(1024) NULL
);

CREATE TABLE languages(
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    description VARCHAR(1024) NULL
);

-- Has many:
CREATE TABLE teacher_experiences(
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    teacher_id VARCHAR(64) REFERENCES teachers(id) ON DELETE CASCADE,
    -- experience type: teaching, education, award:
    experience_type VARCHAR(32) NOT NULL,
    name VARCHAR(200) NOT NULL,
    organization VARCHAR(200) NOT NULL,
    start_year SMALLINT NOT NULL DEFAULT 0,
    end_year SMALLINT NULL
);

-- Has many/through tables:
CREATE TABLE teachers_genres(
    teacher_id VARCHAR(64) REFERENCES teachers(id) ON DELETE CASCADE,
    genre_id VARCHAR(64) REFERENCES genres(id) ON DELETE CASCADE
);
CREATE TABLE teachers_instruments(
    teacher_id VARCHAR(64) REFERENCES teachers(id) ON DELETE CASCADE,
    instrument_id VARCHAR(64) REFERENCES instruments(id) ON DELETE CASCADE
);
CREATE TABLE teachers_subjects(
    teacher_id VARCHAR(64) REFERENCES teachers(id) ON DELETE CASCADE,
    subject_id VARCHAR(64) REFERENCES subjects(id) ON DELETE CASCADE
);
CREATE TABLE teachers_languages(
    teacher_id VARCHAR(64) REFERENCES teachers(id) ON DELETE CASCADE,
    language_id VARCHAR(64) REFERENCES languages(id) ON DELETE CASCADE
);

