create table if not exists members (
    member_id        bigint       primary key,
    email            varchar(255) not null,
    name             varchar(255) not null,
    password         varchar(255) not null,
    role             varchar(20)  not null,
    created_at       timestamp    null,
    last_modified_at timestamp    null
);

create table if not exists themes (
    theme_id         bigint       primary key,
    description      varchar(255) not null,
    name             varchar(255) not null,
    thumbnail        varchar(255) not null,
    created_at       timestamp    null,
    last_modified_at timestamp    null
);

create table if not exists times (
    time_id          bigint    primary key,
    start_at         time      not null,
    created_at       timestamp null,
    last_modified_at timestamp null
);

create table if not exists reservations (
    reservation_id     bigint      primary key,
    date               date        not null,
    member_id          bigint      not null,
    theme_id           bigint      not null,
    time_id            bigint      not null,
    status             varchar(30) not null,
    created_at         timestamp   null,
    last_modified_at   timestamp   null,
    constraint fk_reservations__themeId foreign key (theme_id) references themes (theme_id),
    constraint fk_reservations__memberId foreign key (member_id) references members (member_id),
    constraint fk_reservations__timeId foreign key (time_id) references times (time_id)
);

create table if not exists payments (
    payment_id       bigint       primary key,
    approved_at      timestamp    not null,
    reservation_id   bigint       not null,
    total_amount     bigint       not null,
    order_id         varchar(255) not null,
    payment_key      varchar(255) not null,
    created_at       timestamp    null,
    last_modified_at timestamp    null,
    constraint uk_payments__reservationId unique (reservation_id),
    constraint fk_payments__reservationId foreign key (reservation_id) references reservations (reservation_id)
);

create table if not exists canceled_payments (
    canceled_payment_id bigint       primary key,
    payment_key         varchar(255) not null,
    cancel_reason       varchar(255) not null,
    cancel_amount       bigint       not null,
    approved_at         timestamp    not null,
    canceled_at         timestamp    not null,
    created_at          timestamp    null,
    last_modified_at    timestamp    null
);
