CREATE TABLE IF NOT EXISTS YclientsAccounts (
    ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
    AccountID VARCHAR(30) NOT NULL DEFAULT '', -- ID аккаунта у нас
    YclientsID INT NOT NULL,                        -- ID "компании"
    Name VARCHAR(512) NOT NULL DEFAULT '',
    Country VARCHAR(50) NOT NULL DEFAULT '',
    Deleted BOOLEAN NOT NULL DEFAULT FALSE,
    CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    Subdomain VARCHAR(50) NOT NULL DEFAULT '' -- поддомен - пример https://penadigitaltech.amocrm.ru
);

CREATE TABLE IF NOT EXISTS YclientsAccountUsers (
    ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
    YclientsID INT NOT NULL,                        -- ID компании в Yclients
    YclientsUserID INT NOT NULL,                    -- ID пользователя в Yclients
    Name VARCHAR(512) NOT NULL DEFAULT '',
    Role INT NOT NULL DEFAULT 0, -- position
    Deleted BOOLEAN NOT NULL DEFAULT FALSE,
    CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS YclientsCompany (
    ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
    YclientsID INT NOT NULL,                        -- ID "компании"
    YclientsCompanyID INT NOT NULL,
    Title text NOT NULL,
    ShortDecription text NOT NULL,
    Active INT NOT NULL,
    Country text NOT NULL,
    GroupPriority INT NOT NULL,
    Deleted BOOLEAN NOT NULL DEFAULT FALSE,
    CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS YclientsServices (
    ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
    YclientsID INT NOT NULL,                        -- ID "компании"
    ServiceID INT NOT NULL,
    Title text NOT NULL,
    CategoryID INT NOT NULL,
    PriceMin text NOT NULL,
    PriceMax text NOT NULL,
    Discount text NOT NULL,
    Comment text NOT NULL,
    Active text NOT NULL,
    ApiID text NOT NULL,
    Deleted BOOLEAN NOT NULL DEFAULT FALSE,
    CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)