--- infobip

create table infobip_channels (
    id number(19) primary key references channels(id),
    uuid varchar2(255 char),
    phone varchar2(255 char),
    deleted number(1),

    created_at timestamp with time zone not null,
    updated_at timestamp with time zone not null,
    deleted_at timestamp with time zone,
    restored_at timestamp with time zone
);

create unique index infobip_channels_uuid_ix on infobip_channels(uuid);

-- configs

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

    url varchar2(255 char),
    phone varchar2(255 char),
    username varchar2(255 char),
    password varchar2(255 char),

    scenario_key varchar2(255 char)
);

-- users

create table infobip_users (
    id number(19) primary key,
    phone varchar2(255 char) not null,
    name varchar2(255 char),

    created_at timestamp with time zone not null,
    updated_at timestamp with time zone 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 number(19) primary key,
    chat_id number(19) not null references chats(id),
    user_id number(19) not null references infobip_users(id),

    created_at timestamp with time zone not null,
    updated_at timestamp with time zone not null
);

create sequence infobip_chats_id_seq;
