CREATE TABLE chat_bot_platforms (
    id          NUMBER(19) PRIMARY KEY,
    project_id  NUMBER(19)               NOT NULL REFERENCES projects (id),
    type        VARCHAR2(64 CHAR)        NOT NULL,
    title       VARCHAR2(64 CHAR)        NOT NULL,
    description VARCHAR2(255 CHAR),
    url         VARCHAR2(255 CHAR)       NOT NULL,
    login       VARCHAR2(50 CHAR),
    password    VARCHAR2(50 CHAR),

    enabled     NUMBER(1)                NOT NULL,
    deleted     NUMBER(1)                NOT NULL,

    created_at  TIMESTAMP WITH TIME ZONE NOT NULL,
    updated_at  TIMESTAMP WITH TIME ZONE NOT NULL,
    deleted_at  TIMESTAMP WITH TIME ZONE
);

CREATE SEQUENCE chat_bot_platforms_id_seq;

CREATE UNIQUE INDEX chat_bot_platforms_uniq ON chat_bot_platforms (
    CASE WHEN deleted = 0
        THEN project_id
    END,
    CASE WHEN deleted = 0
        THEN LOWER(title)
    END
);
