-- viber-channels

CREATE TABLE IF NOT EXISTS viber_channels
(
    id bigint primary key NOT NULL,
    uuid character varying(36),
    deleted boolean NOT NULL,
    user_name character varying(1024),
    user_id character varying(256),
    icon character varying(512),
    uri character varying,
    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 IF NOT EXISTS viber_chats
(
    id bigint PRIMARY KEY NOT NULL,
    chat_id bigint 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 IF NOT EXISTS viber_chats_chat_uniq
    ON viber_chats(chat_id);

-- viber_congigs

CREATE TABLE IF NOT EXISTS viber_configs
(
    channel_id bigint PRIMARY KEY NOT NULL REFERENCES channels(id),
    bot_token character varying(255)
);

-- viber users

CREATE TABLE IF NOT EXISTS viber_users
(
    id bigint PRIMARY KEY NOT NULL,
    viber_id character varying(256),
    name character varying(512),
    avatar character varying,
    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 IF NOT EXISTS viber_users_id_viber_id_uniq ON viber_users(id, viber_id);

