--- status-resolutions
create table status_types (
    id bigint identity(1, 1) primary key,
    name nvarchar(255) not null,
    editable_resolutions bit not null default 0,
    weigth bigint not null,

    created_at datetimeoffset not null default SYSDATETIMEOFFSET(),
    updated_at datetimeoffset,
    deleted_at datetimeoffset
)

create unique index uix_status_type on status_types(name);

insert into status_types (name, editable_resolutions, weigth) values ('offline', 0, 4), ('active', 0, 1), ('inactive', 1, 3), ('busy', 1, 2);

create table status_resolutions (
    id bigint identity(1, 1) primary key,
    parent_status_type bigint not null references status_types(id),
    deletable bit not null default 1,
    weigth bigint not null,

    created_at datetimeoffset not null default SYSDATETIMEOFFSET(),
    updated_at datetimeoffset,
    deleted_at datetimeoffset
);

create table status_resolution_titles (
    id bigint primary key identity(1, 1),
    resolution_id bigint not null references status_resolutions(id),
    lang nvarchar(100) not null,
    title nvarchar(255) not null,

    created_at datetimeoffset not null default SYSDATETIMEOFFSET(),
    updated_at datetimeoffset,
    deleted_at datetimeoffset
);

create unique index uix_language_resolution on status_resolution_titles(resolution_id, lang);

insert into status_resolutions (parent_status_type, deletable, weigth) values 
( (select id from status_types where status_types.name = 'offline'), 0, 1 ),
( (select id from status_types where status_types.name = 'active'), 0, 1 ),
( (select id from status_types where status_types.name = 'inactive'), 0, 1),
( (select id from status_types where status_types.name = 'busy'), 0, 1 );

insert into status_resolution_titles (resolution_id, lang, title) values 
(
    (select top 1 id from status_resolutions where status_resolutions.parent_status_type = (select id from status_types where status_types.name = 'offline')),
    'RU', 
    N'Офлайн'
),
(
    (select top 1 id from status_resolutions where status_resolutions.parent_status_type = (select id from status_types where status_types.name = 'offline')),
    'EN', 
    N'Offline'
), 
(
    (select top 1 id from status_resolutions where status_resolutions.parent_status_type = (select id from status_types where status_types.name = 'active')),
    'RU', 
    N'Активен'
), 
(
    (select top 1 id from status_resolutions where status_resolutions.parent_status_type = (select id from status_types where status_types.name = 'active')),
    'EN', 
    N'Active'
),
(
    (select top 1 id from status_resolutions where status_resolutions.parent_status_type = (select id from status_types where status_types.name = 'inactive')),
    'RU', 
    N'Перерыв'
), 
(
    (select top 1 id from status_resolutions where status_resolutions.parent_status_type = (select id from status_types where status_types.name = 'inactive')),
    'EN', 
    N'Break'
), 
(
    (select top 1 id from status_resolutions where status_resolutions.parent_status_type = (select id from status_types where status_types.name = 'busy')),
    'RU', 
    N'Не принимаю чаты'
),
(
    (select top 1 id from status_resolutions where status_resolutions.parent_status_type = (select id from status_types where status_types.name = 'busy')),
    'EN', 
    N'Not accepting new tickets'
);
