-- CreateTable
CREATE TABLE `Download` (
    `id` VARCHAR(191) NOT NULL,
    `uuid` VARCHAR(191) NOT NULL,
    `url` TEXT NOT NULL,
    `status` ENUM('PENDING', 'PROCESSING', 'DONE', 'FAILED', 'FILE_DELETED') NOT NULL DEFAULT 'PENDING',
    `format` VARCHAR(191) NOT NULL,
    `quality` VARCHAR(191) NOT NULL,
    `subtitles` BOOLEAN NOT NULL DEFAULT false,
    `extraArgs` TEXT NULL,
    `filePath` TEXT NULL,
    `fileName` VARCHAR(191) NULL,
    `fileSize` BIGINT NULL,
    `errorMsg` TEXT NULL,
    `ipAddress` VARCHAR(191) NOT NULL,
    `submittedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `startedAt` DATETIME(3) NULL,
    `completedAt` DATETIME(3) NULL,
    `deletedAt` DATETIME(3) NULL,

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

-- CreateTable
CREATE TABLE `DownloadToken` (
    `id` VARCHAR(191) NOT NULL,
    `downloadId` VARCHAR(191) NOT NULL,
    `token` VARCHAR(191) NOT NULL,
    `expiresAt` DATETIME(3) NOT NULL,
    `usedAt` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- AddForeignKey
ALTER TABLE `DownloadToken` ADD CONSTRAINT `DownloadToken_downloadId_fkey` FOREIGN KEY (`downloadId`) REFERENCES `Download`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
