-- CreateTable
CREATE TABLE `User` (
    `id` VARCHAR(191) NOT NULL,
    `email` VARCHAR(191) NOT NULL,
    `celphone` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `password` VARCHAR(191) NOT NULL,
    `active` BOOLEAN NOT NULL DEFAULT true,
    `role` VARCHAR(191) NOT NULL DEFAULT 'user',
    `nEmpresasDisp` INTEGER NULL DEFAULT 1,
    `nInstancesDisp` INTEGER NULL DEFAULT 1,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `User_email_key`(`email`),
    UNIQUE INDEX `User_celphone_key`(`celphone`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Empresa` (
    `id` VARCHAR(191) NOT NULL,
    `idSistema` VARCHAR(191) NOT NULL,
    `apelido` VARCHAR(191) NOT NULL,
    `razaoSocial` VARCHAR(191) NOT NULL,
    `cnpj` VARCHAR(191) NOT NULL,
    `cep` VARCHAR(191) NOT NULL,
    `endereco` VARCHAR(191) NOT NULL,
    `telefone` VARCHAR(191) NOT NULL,
    `tipoProjecao` VARCHAR(191) NOT NULL DEFAULT 'RUA',
    `tipoMeta` VARCHAR(191) NOT NULL DEFAULT 'VENDA',
    `meta` DOUBLE NOT NULL DEFAULT 100000,
    `metaVendedores` VARCHAR(191) NOT NULL DEFAULT '[]',
    `ativo` BOOLEAN NOT NULL DEFAULT true,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,

    INDEX `Empresa_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Cache` (
    `id` VARCHAR(191) NOT NULL,
    `key` VARCHAR(191) NOT NULL,
    `value` LONGTEXT NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `Cache_key_key`(`key`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CacheNumber` (
    `id` VARCHAR(191) NOT NULL,
    `key` VARCHAR(191) NOT NULL,
    `value` LONGTEXT NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `CacheNumber_key_key`(`key`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `UserConnect` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `tipoConexao` VARCHAR(191) NOT NULL,
    `nome` VARCHAR(191) NOT NULL,
    `token` TEXT NOT NULL,
    `url` VARCHAR(191) NOT NULL,
    `userLogin` TEXT NULL,
    `password` TEXT NULL,
    `database` TEXT NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `UserConnect_userId_key`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Configuracao` (
    `id` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `value` TEXT NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `Configuracao_name_key`(`name`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `EstoqueGrifeFornecedor` (
    `id` VARCHAR(191) NOT NULL,
    `tag` VARCHAR(191) NOT NULL,
    `nome` VARCHAR(191) NOT NULL,
    `fornecedor` VARCHAR(191) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `EstoqueGrifeFornecedor_tag_key`(`tag`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `BotInstance` (
    `id` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `empresaId` VARCHAR(191) NULL,
    `userAdminId` VARCHAR(191) NOT NULL,
    `status` VARCHAR(191) NOT NULL,
    `autoOn` BOOLEAN NOT NULL DEFAULT false,
    `group` VARCHAR(191) NOT NULL,
    `groupId` VARCHAR(191) NOT NULL,
    `groupAdmin` VARCHAR(191) NOT NULL,
    `groupAdminId` VARCHAR(191) NULL,
    `enviosAdicionais` JSON NULL,
    `horaEnvio` VARCHAR(191) NULL DEFAULT '09',
    `ddd` VARCHAR(191) NOT NULL DEFAULT '11',
    `adminNumber` VARCHAR(191) NOT NULL,
    `botDiscountMinAlert` BOOLEAN NULL DEFAULT false,
    `botDiscountMinAlertValue` DOUBLE NULL DEFAULT 15,
    `botDiscountLastSaleCode` INTEGER NULL,
    `botDailyResume` BOOLEAN NULL DEFAULT false,
    `botRegua` BOOLEAN NULL DEFAULT false,
    `connected` BOOLEAN NULL DEFAULT false,
    `telegram` BOOLEAN NULL DEFAULT false,
    `diasEnvioResumo` VARCHAR(191) NULL DEFAULT '[1,2,3,4,5]',
    `empresasResumo` VARCHAR(191) NULL DEFAULT '[]',
    `isInstancePrincipal` BOOLEAN NULL DEFAULT false,
    `others` JSON NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `BotInstance_name_key`(`name`),
    INDEX `BotInstance_empresaId_idx`(`empresaId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Campaign` (
    `id` VARCHAR(191) NOT NULL,
    `status` VARCHAR(191) NOT NULL,
    `type` VARCHAR(191) NOT NULL,
    `empresasIds` JSON NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `title` VARCHAR(191) NOT NULL,
    `message` TEXT NOT NULL,
    `path` TEXT NULL,
    `filter` TEXT NULL,
    `daily` BOOLEAN NULL DEFAULT false,
    `limit` INTEGER NULL DEFAULT 0,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CampaignList` (
    `id` VARCHAR(191) NOT NULL,
    `campaignId` VARCHAR(191) NOT NULL,
    `store` VARCHAR(191) NOT NULL,
    `list` JSON NOT NULL,
    `total` INTEGER NOT NULL,
    `enviados` INTEGER NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Message` (
    `id` VARCHAR(191) NOT NULL,
    `instanceId` VARCHAR(191) NOT NULL,
    `campaignId` VARCHAR(191) NOT NULL,
    `type` VARCHAR(191) NOT NULL,
    `to` VARCHAR(191) NULL,
    `from` VARCHAR(191) NULL,
    `messageId` VARCHAR(191) NULL,
    `status` VARCHAR(191) NULL,
    `updatedAt` DATETIME(3) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `Message_campaignId_idx`(`campaignId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Conversation` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `threadId` VARCHAR(191) NULL DEFAULT '',
    `contextData` JSON NULL,
    `messages` JSON NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `Conversation_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CatalogoDigitalLentes` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NULL,
    `cod_dataweb` VARCHAR(191) NULL,
    `nome_lente` VARCHAR(255) NOT NULL,
    `fornecedor` VARCHAR(191) NOT NULL,
    `tipo` VARCHAR(191) NULL,
    `tratamento` VARCHAR(191) NULL,
    `cor` VARCHAR(191) NULL,
    `refracao` DECIMAL(4, 2) NULL,
    `material` VARCHAR(191) NULL,
    `indicacao` TEXT NULL,
    `categorias` TEXT NULL,
    `tags` TEXT NULL,
    `esferico_min` DECIMAL(4, 2) NULL,
    `esferico_max` DECIMAL(4, 2) NULL,
    `cilindro_min` DECIMAL(4, 2) NULL,
    `adicao_min` DECIMAL(4, 2) NULL,
    `adicao_max` DECIMAL(4, 2) NOT NULL,
    `preco_venda` DECIMAL(10, 2) NULL,
    `data_criacao` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
    `data_att_bd` DATETIME(3) NULL,
    `ativa` INTEGER NULL DEFAULT 0,
    `diametro` VARCHAR(191) NULL,
    `peso` DECIMAL(10, 2) NULL DEFAULT 0.00,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CatalogoDigitalLentes_Personalizacao` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(36) NULL,
    `categoria` VARCHAR(50) NOT NULL,
    `identificador` VARCHAR(100) NOT NULL,
    `estilos` JSON NULL,
    `ativo` BOOLEAN NOT NULL DEFAULT true,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `CatalogoDigitalLentes_Personalizacao_userId_idx`(`userId`),
    UNIQUE INDEX `CatalogoDigitalLentes_Personalizacao_categoria_identificador_key`(`categoria`, `identificador`, `userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CatalogoDigitalLentes_Midia` (
    `id` VARCHAR(191) NOT NULL,
    `personalizacaoId` VARCHAR(191) NOT NULL,
    `tipo` VARCHAR(191) NOT NULL,
    `url` VARCHAR(191) NOT NULL,
    `ordem` INTEGER NOT NULL DEFAULT 0,
    `ativo` BOOLEAN NOT NULL DEFAULT true,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CatalogoDigitalLentes_Favoritos` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `lentes` JSON NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `CatalogoDigitalLentes_Favoritos_userId_key`(`userId`),
    INDEX `CatalogoDigitalLentes_Favoritos_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CatalogoDigitalLentes_FiltrosPadroes` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `filtros` JSON NOT NULL,
    `ativo` BOOLEAN NOT NULL DEFAULT true,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `CatalogoDigitalLentes_FiltrosPadroes_userId_key`(`userId`),
    INDEX `CatalogoDigitalLentes_FiltrosPadroes_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CatalogoDigitalLentes_Compartilhamento` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `token` VARCHAR(191) NOT NULL,
    `senha` VARCHAR(191) NULL,
    `expiraEm` DATETIME(3) NULL,
    `tipoAcesso` VARCHAR(191) NOT NULL DEFAULT 'PUBLICO',
    `filtros` JSON NULL,
    `ativo` BOOLEAN NOT NULL DEFAULT true,
    `visualizacoes` INTEGER NOT NULL DEFAULT 0,
    `ultimoAcesso` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `CatalogoDigitalLentes_Compartilhamento_token_key`(`token`),
    INDEX `CatalogoDigitalLentes_Compartilhamento_userId_idx`(`userId`),
    INDEX `CatalogoDigitalLentes_Compartilhamento_token_idx`(`token`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `UserColaborator` (
    `id` VARCHAR(191) NOT NULL,
    `adminId` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `status` VARCHAR(191) NOT NULL DEFAULT 'PENDING',
    `inviteToken` VARCHAR(100) NULL,
    `tokenHash` VARCHAR(64) NULL,
    `inviteExpires` DATETIME(3) NULL,
    `permissionGroupId` VARCHAR(191) NULL,
    `permissionStores` JSON NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `UserColaborator_userId_key`(`userId`),
    UNIQUE INDEX `UserColaborator_tokenHash_key`(`tokenHash`),
    INDEX `UserColaborator_adminId_idx`(`adminId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Permission` (
    `id` VARCHAR(191) NOT NULL,
    `name` VARCHAR(100) NOT NULL,
    `nameHash` VARCHAR(64) NOT NULL,
    `description` TEXT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `Permission_nameHash_key`(`nameHash`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `PermissionGroup` (
    `id` VARCHAR(191) NOT NULL,
    `name` VARCHAR(100) NOT NULL,
    `nameHash` VARCHAR(64) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `PermissionGroupPermission` (
    `id` VARCHAR(191) NOT NULL,
    `permissionId` VARCHAR(191) NOT NULL,
    `permissionGroupId` VARCHAR(191) NOT NULL,

    INDEX `PermissionGroupPermission_permissionId_idx`(`permissionId`),
    INDEX `PermissionGroupPermission_permissionGroupId_idx`(`permissionGroupId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Garantia` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `tipo` VARCHAR(191) NOT NULL,
    `dataGarantia` DATETIME(3) NOT NULL,
    `dataPrevisao` DATETIME(3) NOT NULL,
    `responsavel` VARCHAR(191) NOT NULL,
    `osDiversos` VARCHAR(191) NOT NULL,
    `numeroDevolucao` VARCHAR(191) NOT NULL,
    `vendaOs` VARCHAR(191) NOT NULL,
    `vendaLoja` VARCHAR(191) NOT NULL,
    `vendaData` DATETIME(3) NOT NULL,
    `clienteId` VARCHAR(191) NOT NULL,
    `clienteNome` VARCHAR(191) NOT NULL,
    `clienteCpf` VARCHAR(191) NOT NULL,
    `produtoTipo` VARCHAR(191) NOT NULL,
    `produtoCodigo` VARCHAR(191) NOT NULL,
    `produtoMarca` VARCHAR(191) NOT NULL,
    `produtoDescricao` VARCHAR(191) NOT NULL,
    `produtoReferencia` VARCHAR(191) NOT NULL,
    `produtoCaracteristicas` VARCHAR(191) NOT NULL,
    `produtoParteDefeito` VARCHAR(191) NOT NULL,
    `produtoDefeito` VARCHAR(191) NOT NULL,
    `produtoLcCliente` VARCHAR(191) NOT NULL,
    `produtoLcEstado` VARCHAR(191) NOT NULL,
    `produtoClienteDeixou` VARCHAR(191) NOT NULL,
    `produtoFoto` VARCHAR(191) NOT NULL,
    `observacao` VARCHAR(191) NOT NULL,
    `fornecedor` VARCHAR(191) NOT NULL,
    `nfCompra` VARCHAR(191) NOT NULL,
    `nfEmissao` DATETIME(3) NOT NULL,
    `empresa` VARCHAR(191) NOT NULL,
    `custo` VARCHAR(191) NOT NULL,
    `backObservacao` VARCHAR(191) NOT NULL,
    `devolucaoNf` VARCHAR(191) NOT NULL,
    `devolucaoData` DATETIME(3) NOT NULL,
    `finalLoja` VARCHAR(191) NOT NULL,
    `finalCliente` VARCHAR(191) NOT NULL,
    `finalFornecedor` VARCHAR(191) NOT NULL,
    `fornecedorTipo` VARCHAR(191) NOT NULL,
    `statusAtual` VARCHAR(191) NOT NULL,
    `dataCriacao` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `GarantiaHistorico` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `data` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `status` VARCHAR(191) NOT NULL,
    `responsavel` VARCHAR(191) NOT NULL,
    `observacoes` VARCHAR(191) NULL,
    `garantiaId` INTEGER NOT NULL,
    `descricao` VARCHAR(191) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `GarantiaReceita` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `garantiaId` INTEGER NOT NULL,
    `olho` VARCHAR(191) NOT NULL,
    `longeEsferico` VARCHAR(191) NULL,
    `longeCilindrico` VARCHAR(191) NULL,
    `longeEixo` VARCHAR(191) NULL,
    `pertoEsferico` VARCHAR(191) NULL,
    `pertoCilindrico` VARCHAR(191) NULL,
    `pertoEixo` VARCHAR(191) NULL,
    `altura` VARCHAR(191) NULL,
    `tamanhoAro` VARCHAR(191) NULL,
    `vertical` VARCHAR(191) NULL,
    `md` VARCHAR(191) NULL,
    `ponte` VARCHAR(191) NULL,
    `responsavel` VARCHAR(191) NOT NULL,
    `observacoes` VARCHAR(191) NULL,
    `dataCriacao` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `TokenGarantia` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `token` VARCHAR(4) NOT NULL,
    `dataGerou` DATETIME(3) NOT NULL,
    `gerouResponsavel` VARCHAR(191) NOT NULL,
    `observacao` VARCHAR(191) NOT NULL,
    `usouLoja` VARCHAR(191) NOT NULL,
    `usouGarantia` VARCHAR(191) NOT NULL,
    `usouResponsavel` VARCHAR(191) NOT NULL,
    `dataUsou` DATETIME(3) NOT NULL,
    `dataCriacao` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Token` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `token` CHAR(4) NOT NULL,
    `observacoes` TEXT NULL,
    `responsavel` VARCHAR(191) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `Token_token_key`(`token`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `LogAcessos` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `userId` VARCHAR(191) NULL,
    `accessPage` VARCHAR(191) NULL,
    `params` LONGTEXT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `Empresa` ADD CONSTRAINT `Empresa_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `UserConnect` ADD CONSTRAINT `UserConnect_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `BotInstance` ADD CONSTRAINT `BotInstance_empresaId_fkey` FOREIGN KEY (`empresaId`) REFERENCES `Empresa`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Message` ADD CONSTRAINT `Message_campaignId_fkey` FOREIGN KEY (`campaignId`) REFERENCES `Campaign`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Conversation` ADD CONSTRAINT `Conversation_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CatalogoDigitalLentes_Midia` ADD CONSTRAINT `CatalogoDigitalLentes_Midia_personalizacaoId_fkey` FOREIGN KEY (`personalizacaoId`) REFERENCES `CatalogoDigitalLentes_Personalizacao`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `UserColaborator` ADD CONSTRAINT `UserColaborator_adminId_fkey` FOREIGN KEY (`adminId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `UserColaborator` ADD CONSTRAINT `UserColaborator_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `UserColaborator` ADD CONSTRAINT `UserColaborator_permissionGroupId_fkey` FOREIGN KEY (`permissionGroupId`) REFERENCES `PermissionGroup`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PermissionGroup` ADD CONSTRAINT `PermissionGroup_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PermissionGroupPermission` ADD CONSTRAINT `PermissionGroupPermission_permissionId_fkey` FOREIGN KEY (`permissionId`) REFERENCES `Permission`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PermissionGroupPermission` ADD CONSTRAINT `PermissionGroupPermission_permissionGroupId_fkey` FOREIGN KEY (`permissionGroupId`) REFERENCES `PermissionGroup`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `GarantiaHistorico` ADD CONSTRAINT `GarantiaHistorico_garantiaId_fkey` FOREIGN KEY (`garantiaId`) REFERENCES `Garantia`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `GarantiaReceita` ADD CONSTRAINT `GarantiaReceita_garantiaId_fkey` FOREIGN KEY (`garantiaId`) REFERENCES `Garantia`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
