
create table identification_rules(
    id BIGINT IDENTITY (1,1) PRIMARY KEY,
    title nvarchar(100) not null,
    project_id bigint references projects(id),
    channel_id bigint references channels(id),
    "order" integer not null,
    active bit not null,
    enabled bit not null,
    deleted bit not null,
    success_message nvarchar(4000),
    identify_by nvarchar(100) not null,
    ask_identificator bit not null,
    identification_question nvarchar(1000),
    created_at datetimeoffset NOT NULL,
    updated_at datetimeoffset NOT NULL,
    deleted_at datetimeoffset
);
create index identification_rules_project_id on identification_rules(project_id);
create index identification_rules_channel_id on identification_rules(channel_id);

create table client_identifications(
                                       client_id BIGINT not null references clients(id),
                                       last_ticket_id BIGINT not null references tickets(id),
                                       status varchar(200) not null,
                                       secret_word_validator NVARCHAR(200),
                                       failed_rule_id BIGINT,
                                       created_at DATETIMEOFFSET NOT NULL,
                                       updated_at DATETIMEOFFSET NOT NULL
);
create index client_identifications_client_id on client_identifications(client_id);