-- CreateTable
CREATE TABLE `ShopVisit` (
    `id` VARCHAR(36) NOT NULL,
    `visitDate` DATE NOT NULL,
    `bookerId` VARCHAR(36) NOT NULL,
    `shopId` VARCHAR(36) NOT NULL,
    `companyId` VARCHAR(36) NOT NULL,
    `status` ENUM('PENDING', 'ORDERED', 'NO_ORDER', 'MISSED') NOT NULL DEFAULT 'PENDING',
    `proofImageUrl` VARCHAR(191) NULL,
    `visitedAt` DATETIME(3) NULL,
    `orderId` VARCHAR(36) NULL,
    `reason` VARCHAR(191) NULL,
    `latitude` DOUBLE NULL,
    `longitude` DOUBLE NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `ShopVisit_orderId_key`(`orderId`),
    UNIQUE INDEX `ShopVisit_bookerId_shopId_visitDate_key`(`bookerId`, `shopId`, `visitDate`),
    INDEX `ShopVisit_companyId_idx`(`companyId`),
    INDEX `ShopVisit_bookerId_visitDate_idx`(`bookerId`, `visitDate`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `ShopVisit` ADD CONSTRAINT `ShopVisit_bookerId_fkey` FOREIGN KEY (`bookerId`) REFERENCES `Staff`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ShopVisit` ADD CONSTRAINT `ShopVisit_shopId_fkey` FOREIGN KEY (`shopId`) REFERENCES `Shop`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ShopVisit` ADD CONSTRAINT `ShopVisit_companyId_fkey` FOREIGN KEY (`companyId`) REFERENCES `Company`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ShopVisit` ADD CONSTRAINT `ShopVisit_orderId_fkey` FOREIGN KEY (`orderId`) REFERENCES `Order`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
