CREATE TYPE public."judgement_type" AS ENUM (
    '300',
    '100',
    '50',
    'Miss');
CREATE SEQUENCE public.beatmaps_beatmap_id_seq
    INCREMENT BY 1
    MINVALUE 1
    MAXVALUE 2147483647
    START 1
    CACHE 1
    NO CYCLE;

CREATE SEQUENCE public.scores_id_seq
    INCREMENT BY 1
    MINVALUE 1
    MAXVALUE 2147483647
    START 1
    CACHE 1
    NO CYCLE;

CREATE SEQUENCE public.scores_judgements_id_seq
    INCREMENT BY 1
    MINVALUE 1
    MAXVALUE 2147483647
    START 1
    CACHE 1
    NO CYCLE;

CREATE SEQUENCE public.scores_similarity_id_seq
    INCREMENT BY 1
    MINVALUE 1
    MAXVALUE 2147483647
    START 1
    CACHE 1
    NO CYCLE;

CREATE SEQUENCE public.users_user_id_seq
    INCREMENT BY 1
    MINVALUE 1
    MAXVALUE 9223372036854775807
    START 1
    CACHE 1
    NO CYCLE;

CREATE TABLE public.beatmaps
(
    beatmap_id           serial4   NOT NULL,
    approach_rate        float8    NULL,
    approved             varchar   NULL,
    approved_date        timestamp NULL,
    artist               varchar   NULL,
    audio_unavailable    bool      NULL,
    beatmap_hash         varchar   NULL,
    beatmapset_id        int4      NULL,
    bpm                  varchar   NULL,
    circle_size          float8    NULL,
    count_hitcircles     int4      NULL,
    count_sliders        int4      NULL,
    count_spinners       int4      NULL,
    creator              varchar   NULL,
    creator_id           int4      NULL,
    download_unavailable bool      NULL,
    favourite_count      int4      NULL,
    genre_id             int4      NULL,
    health               float8    NULL,
    hit_length           float8    NULL,
    language_id          int4      NULL,
    last_update          timestamp NULL,
    max_combo            int4      NULL,
    "mode"               int4      NULL,
    overrall_difficulty  float8    NULL,
    passcount            int4      NULL,
    playcount            int4      NULL,
    rating               float8    NULL,
    "source"             varchar   NULL,
    star_rating          float8    NULL,
    stars_aim            float8    NULL,
    stars_speed          float8    NULL,
    storyboard           bool      NULL,
    submit_date          timestamp NULL,
    tags                 varchar   NULL,
    title                varchar   NULL,
    total_length         float8    NULL,
    "version"            varchar   NULL,
    video                bool      NULL,
    sys_last_update      timestamp NULL,
    CONSTRAINT beatmaps_pkey PRIMARY KEY (beatmap_id)
);

CREATE TABLE public.reddit_post
(
    post_id     varchar NOT NULL,
    title       varchar NULL,
    created_utc float8  NULL,
    url         varchar NULL,
    is_checked  bool    NULL DEFAULT false,
    CONSTRAINT reddit_post_pkey PRIMARY KEY (post_id)
);

CREATE TABLE public.scores
(
    id               serial4   NOT NULL,
    beatmap_id       int4      NULL,
    count_100        int4      NULL,
    count_300        int4      NULL,
    count_50         int4      NULL,
    count_geki       int4      NULL,
    count_katu       int4      NULL,
    count_miss       int4      NULL,
    "date"           timestamp NULL,
    max_combo        int4      NULL,
    mods             int4      NULL,
    perfect          bool      NULL,
    pp               float8    NULL,
    "rank"           varchar   NULL,
    replay_available bool      NULL,
    replay_id        int8      NULL,
    score            int8      NULL,
    user_id          int8      NULL,
    username         varchar   NULL,
    replay           bytea     NULL,
    ur               float8    NULL,
    frametime        float8    NULL,
    hits             int4      NULL,
    snaps            int4      NULL,
    is_banned        bool      NULL DEFAULT false,
    CONSTRAINT scores_pkey PRIMARY KEY (id)
);

CREATE TABLE public.scores_similarity
(
    id          serial4   NOT NULL,
    beatmap_id  int4      NULL,
    replay_id_1 int8      NULL,
    replay_id_2 int8      NULL,
    similarity  float8    NULL,
    correlation float8    NULL,
    created_at  timestamp NULL,
    CONSTRAINT scores_similarity_pkey PRIMARY KEY (id)
);
CREATE INDEX idx_replay_ids ON public.scores_similarity USING btree (replay_id_1, replay_id_2);
CREATE INDEX idx_replay_ids_pairs ON public.scores_similarity USING btree (replay_id_1, replay_id_2);

CREATE TABLE public.users
(
    user_id         bigserial NOT NULL,
    username        varchar   NULL,
    join_date       timestamp NULL,
    country         varchar   NULL,
    country_rank    int8      NULL,
    "rank"          int8      NULL,
    pp_raw          float8    NULL,
    "level"         float8    NULL,
    accuracy        float8    NULL,
    playcount       int8      NULL,
    total_score     int8      NULL,
    ranked_score    int8      NULL,
    seconds_played  int8      NULL,
    count_100       int8      NULL,
    count_300       int8      NULL,
    count_50        int8      NULL,
    count_rank_a    int8      NULL,
    count_rank_s    int8      NULL,
    count_rank_sh   int8      NULL,
    count_rank_ss   int8      NULL,
    count_rank_ssh  int8      NULL,
    sys_last_update timestamp NULL,
    CONSTRAINT users_pkey PRIMARY KEY (user_id)
);

CREATE TABLE public.scores_judgements
(
    id              serial4                 NOT NULL,
    "time"          float8                  NULL,
    x               float8                  NULL,
    y               float8                  NULL,
    "type"          public."judgement_type" NULL,
    distance_center float8                  NULL,
    distance_edge   float8                  NULL,
    error           float8                  NULL,
    score_id        int4                    NULL,
    CONSTRAINT scores_judgements_pkey PRIMARY KEY (id),
    CONSTRAINT scores_judgements_score_id_fkey FOREIGN KEY (score_id) REFERENCES public.scores (id) ON DELETE CASCADE
);