-- viber-channels

CREATE TABLE viber_channels
(
    id NUMBER(19) primary key NOT NULL,
    uuid varchar2(36),
    deleted NUMBER(1) NOT NULL,
    user_name varchar2(1024),
    user_id varchar2(256),
    icon varchar2(512),
    uri varchar2(4000),
    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 viber_channels_uuid_uniq
    ON viber_channels(uuid);

CREATE UNIQUE INDEX viber_channels_user_uniq
    ON viber_channels (user_id);

-- viber-chats

CREATE TABLE viber_chats
(
    id NUMBER(19) PRIMARY KEY NOT NULL,
    chat_id NUMBER(19) NOT NULL,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);

CREATE SEQUENCE viber_chats_id_seq;

CREATE UNIQUE INDEX viber_chats_chat_uniq
    ON viber_chats(chat_id);

-- viber_congigs

CREATE TABLE viber_configs
(
    channel_id NUMBER(19) PRIMARY KEY NOT NULL REFERENCES channels(id),
    bot_token varchar2(255)
);

-- viber users

CREATE TABLE viber_users
(
    id NUMBER(19) PRIMARY KEY NOT NULL,
    viber_id varchar2(256),
    name varchar2(512),
    avatar varchar2(4000),
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);

CREATE SEQUENCE viber_users_id_seq;

CREATE UNIQUE INDEX viber_users_id_viber_id_uniq ON viber_users(id, viber_id);

