-- CreateTable
CREATE TABLE `ConnectionStatus` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `status` VARCHAR(191) NOT NULL,
    `timestamp` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

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

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

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

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

-- CreateTable
CREATE TABLE `MessageCampaignList` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `campaignId` INTEGER NOT NULL,
    `store` VARCHAR(191) NULL,
    `customerId` INTEGER NOT NULL,
    `send` BOOLEAN NOT NULL DEFAULT false,
    `sendDate` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE `Customer` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `cod` INTEGER NULL,
    `name` VARCHAR(191) NOT NULL,
    `cpf` VARCHAR(191) NULL,
    `rg` VARCHAR(191) NULL,
    `cep` VARCHAR(191) NULL,
    `street` VARCHAR(191) NULL,
    `number` VARCHAR(191) NULL,
    `complement` VARCHAR(191) NULL,
    `neighborhood` VARCHAR(191) NULL,
    `city` VARCHAR(191) NULL,
    `uf` VARCHAR(191) NULL,
    `tel1` VARCHAR(191) NULL,
    `tel2` VARCHAR(191) NULL,
    `cel` VARCHAR(191) NULL,
    `email` VARCHAR(191) NULL,
    `image` VARCHAR(191) NULL,
    `birthday` DATE NULL,
    `lgpd` BOOLEAN NOT NULL DEFAULT false,
    `department` VARCHAR(191) NULL,
    `notes` TEXT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE `Order` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `store` VARCHAR(191) NOT NULL,
    `orderNumber` INTEGER NOT NULL,
    `internalCode` VARCHAR(191) NOT NULL,
    `description` VARCHAR(191) NOT NULL,
    `quantity` INTEGER NOT NULL,
    `saleValue` DOUBLE NOT NULL,
    `productValue` DOUBLE NOT NULL,
    `saleDiscount` DOUBLE NOT NULL,
    `totalSale` DOUBLE NOT NULL,
    `productCost` DOUBLE NOT NULL,
    `saleDate` DATETIME(3) NOT NULL,
    `customerCode` INTEGER NOT NULL,
    `sellerCode` INTEGER NOT NULL,
    `sellerName` VARCHAR(191) NULL,
    `saleCode` INTEGER NOT NULL,
    `revenueCode` INTEGER NULL,
    `cfop` VARCHAR(191) NOT NULL,
    `observation` TEXT NULL,
    `forecastDate` DATETIME(3) NOT NULL,
    `updating` VARCHAR(191) NULL,
    `creationDate` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE `Instance` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `instanceId` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `store` VARCHAR(191) NOT NULL,
    `storeDw` VARCHAR(191) NULL,
    `status` VARCHAR(191) NOT NULL,
    `autoOn` BOOLEAN NOT NULL DEFAULT false,
    `region` VARCHAR(191) NULL,
    `group` VARCHAR(191) NULL,
    `groupId` VARCHAR(191) NULL,
    `botDiscountLastSaleCode` INTEGER NULL,
    `botDailyResume` BOOLEAN NULL DEFAULT false,
    `botRegua` BOOLEAN NULL DEFAULT false,
    `connected` BOOLEAN NULL DEFAULT false,
    `telegram` BOOLEAN NULL DEFAULT false,
    `document` VARCHAR(191) NOT NULL,
    `ddd` VARCHAR(191) NOT NULL,
    `telephone` VARCHAR(191) NOT NULL,
    `email` VARCHAR(191) NOT NULL,
    `others` JSON NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

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