--- system-status

create type system_status_type as enum ('working_with_tickets');

create table system_statuses
(
    id         bigint generated always as identity primary key,
    user_id    bigint             not null references users (id),
    "type"     system_status_type not null,
    active     boolean            not null,
    started_at timestamptz default timezone('utc', now()),
    ended_at   timestamptz
);

create unique index system_statuses_type_active_uniq
    on statuses (user_id, "type", active) where active is true;

create index system_statuses_started_ix on statuses (started_at);
create index system_statuses_user_started_in on statuses (user_id, started_at);
