-- CreateTable
CREATE TABLE `caseInstance` (
    `caseID` INTEGER NOT NULL AUTO_INCREMENT,
    `caseUUID` VARCHAR(36) NOT NULL,
    `processID` INTEGER NOT NULL,
    `caseName` VARCHAR(255) NOT NULL,
    `caseStatus` VARCHAR(50) NOT NULL DEFAULT 'active',
    `caseStartedBy` INTEGER NULL,
    `caseVariables` JSON NULL,
    `caseSettings` JSON NULL,
    `caseDefinition` JSON NULL,
    `caseCreatedDate` DATETIME(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    `caseModifiedDate` DATETIME(0) NULL,
    `caseCompletedDate` DATETIME(0) NULL,

    UNIQUE INDEX `caseInstance_caseUUID_key`(`caseUUID`),
    INDEX `FK_case_process`(`processID`),
    INDEX `FK_case_startedBy`(`caseStartedBy`),
    INDEX `IDX_case_status`(`caseStatus`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `task` (
    `taskID` INTEGER NOT NULL AUTO_INCREMENT,
    `taskUUID` VARCHAR(36) NOT NULL,
    `caseID` INTEGER NOT NULL,
    `taskName` VARCHAR(255) NOT NULL,
    `taskType` VARCHAR(50) NOT NULL,
    `taskStatus` VARCHAR(50) NOT NULL DEFAULT 'pending',
    `taskAssignedTo` INTEGER NULL,
    `taskFormID` INTEGER NULL,
    `taskData` JSON NULL,
    `taskCreatedDate` DATETIME(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    `taskModifiedDate` DATETIME(0) NULL,
    `taskCompletedDate` DATETIME(0) NULL,

    UNIQUE INDEX `task_taskUUID_key`(`taskUUID`),
    INDEX `FK_task_case`(`caseID`),
    INDEX `FK_task_assignedTo`(`taskAssignedTo`),
    INDEX `FK_task_form`(`taskFormID`),
    INDEX `IDX_task_status`(`taskStatus`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `caseTimeline` (
    `timelineID` INTEGER NOT NULL AUTO_INCREMENT,
    `caseID` INTEGER NOT NULL,
    `timelineType` VARCHAR(50) NOT NULL,
    `timelineDescription` TEXT NULL,
    `timelineDate` DATETIME(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    `timelineCreatedBy` INTEGER NULL,

    INDEX `FK_caseTimeline_case`(`caseID`),
    INDEX `FK_caseTimeline_createdBy`(`timelineCreatedBy`),
    INDEX `IDX_caseTimeline_date`(`timelineDate`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 