--- infobip

create table infobip_channels (
    id bigint primary key references channels(id),
    uuid varchar(255),
    phone varchar(255),
    deleted boolean,

    created_at timestamptz not null,
    updated_at timestamptz not null,
    deleted_at timestamptz,
    restored_at timestamptz
);

create unique index infobip_channels_uuid_ix on infobip_channels(uuid);

-- configs

create table infobip_configs (
    channel_id bigint primary key references infobip_channels(id),

    url varchar(255),
    phone varchar(255),
    username varchar(255),
    password varchar(255),

    scenario_key varchar(255)
);

-- users

create table infobip_users (
    id bigint primary key,
    phone varchar(255) not null,
    name varchar(255),

    created_at timestamptz not null,
    updated_at timestamptz not null
);

create sequence infobip_users_id_seq;

create unique index infobip_users_phone_ix on infobip_users(phone);

-- chats

create table infobip_chats (
    id bigint primary key,
    chat_id bigint not null references chats(id),
    user_id bigint not null references infobip_users(id),

    created_at timestamptz not null,
    updated_at timestamptz not null
);

create sequence infobip_chats_id_seq;
