/*
  Warnings:

  - A unique constraint covering the columns `[sipIdentity]` on the table `User` will be added. If there are existing duplicate values, this will fail.

*/
-- AlterTable
ALTER TABLE `callleg` ADD COLUMN `connectedAt` DATETIME(3) NULL;

-- AlterTable
ALTER TABLE `callsession` ADD COLUMN `conferenceName` VARCHAR(191) NULL,
    ADD COLUMN `recordingDuration` INTEGER NULL,
    ADD COLUMN `recordingUrl` VARCHAR(191) NULL;

-- AlterTable
ALTER TABLE `message` MODIFY `status` ENUM('sent', 'delivered', 'failed', 'received', 'read') NOT NULL DEFAULT 'sent';

-- AlterTable
ALTER TABLE `user` ADD COLUMN `additionalRoleId` INTEGER NULL,
    ADD COLUMN `autoDialEnabled` BOOLEAN NOT NULL DEFAULT false,
    ADD COLUMN `twoFAEnabled` BOOLEAN NOT NULL DEFAULT false,
    ADD COLUMN `twoFASecret` VARCHAR(191) NULL;

-- CreateTable
CREATE TABLE `UserSession` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `userId` INTEGER NOT NULL,
    `tokenVersion` VARCHAR(191) NOT NULL,
    `deviceId` VARCHAR(191) NULL,
    `deviceName` VARCHAR(191) NULL,
    `ipAddress` VARCHAR(191) NULL,
    `userAgent` TEXT NULL,
    `socketId` VARCHAR(191) NULL,
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `revokedAt` DATETIME(3) NULL,
    `lastSeenAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `UserSession_tokenVersion_key`(`tokenVersion`),
    INDEX `UserSession_userId_idx`(`userId`),
    INDEX `UserSession_isActive_idx`(`isActive`),
    INDEX `UserSession_tokenVersion_idx`(`tokenVersion`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `PasswordResetToken` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `userId` INTEGER NOT NULL,
    `token` VARCHAR(191) NOT NULL,
    `expiresAt` DATETIME(3) NOT NULL,
    `used` BOOLEAN NOT NULL DEFAULT false,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `PasswordResetToken_token_key`(`token`),
    INDEX `PasswordResetToken_userId_idx`(`userId`),
    INDEX `PasswordResetToken_token_idx`(`token`),
    INDEX `PasswordResetToken_expiresAt_idx`(`expiresAt`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CallRecordingTemp` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `recordingSid` VARCHAR(191) NOT NULL,
    `conferenceName` VARCHAR(191) NOT NULL,
    `status` VARCHAR(191) NOT NULL,

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

-- CreateTable
CREATE TABLE `CallTranscript` (
    `id` VARCHAR(191) NOT NULL,
    `callSessionId` INTEGER NOT NULL,
    `speaker` VARCHAR(191) NOT NULL,
    `text` VARCHAR(191) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `CallTranscript_callSessionId_idx`(`callSessionId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `AgentPrivilege` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `userId` INTEGER NOT NULL,
    `makeCall` BOOLEAN NOT NULL DEFAULT false,
    `transcription` BOOLEAN NOT NULL DEFAULT false,
    `transfer` BOOLEAN NOT NULL DEFAULT false,
    `recording` BOOLEAN NOT NULL DEFAULT false,
    `loginIp` BOOLEAN NOT NULL DEFAULT false,
    `loginIpAddress` VARCHAR(191) NULL,
    `mms` BOOLEAN NOT NULL DEFAULT false,
    `twoFA` BOOLEAN NOT NULL DEFAULT false,
    `endCallPop` BOOLEAN NOT NULL DEFAULT false,
    `emailPrivilege` BOOLEAN NOT NULL DEFAULT false,
    `additionalEmail` VARCHAR(191) NULL,
    `targetEnable` BOOLEAN NOT NULL DEFAULT false,
    `targetValue` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

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

-- CreateTable
CREATE TABLE `AgentSmtp` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `userId` INTEGER NOT NULL,
    `host` VARCHAR(191) NOT NULL,
    `port` INTEGER NOT NULL,
    `secure` BOOLEAN NOT NULL,
    `username` VARCHAR(191) NOT NULL,
    `password` VARCHAR(191) NOT NULL,
    `fromEmail` VARCHAR(191) NOT NULL,
    `fromName` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

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

-- CreateTable
CREATE TABLE `VerificationCode` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `userId` INTEGER NOT NULL,
    `code` VARCHAR(6) NOT NULL,
    `expiresAt` DATETIME(3) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE `Lead` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `clientName` VARCHAR(191) NOT NULL,
    `clientPhone` VARCHAR(191) NOT NULL,
    `clientAddress` VARCHAR(191) NULL,
    `dispositionId` INTEGER NULL,
    `nextFollowupDate` DATETIME(3) NULL,
    `alternatePhone` VARCHAR(191) NULL,
    `comments` VARCHAR(191) NULL,
    `tags` JSON NULL,
    `addedById` INTEGER NOT NULL,
    `callSessionId` INTEGER NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `Lead_clientPhone_idx`(`clientPhone`),
    INDEX `Lead_addedById_idx`(`addedById`),
    INDEX `Lead_dispositionId_idx`(`dispositionId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Sale` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `clientName` VARCHAR(191) NOT NULL,
    `clientPhone` VARCHAR(191) NOT NULL,
    `clientAddress` VARCHAR(191) NULL,
    `services` JSON NOT NULL,
    `amount` DOUBLE NOT NULL,
    `currency` VARCHAR(191) NOT NULL,
    `paymentType` VARCHAR(191) NOT NULL,
    `billingDate` DATETIME(3) NULL,
    `businessName` VARCHAR(191) NULL,
    `businessAddress` VARCHAR(191) NULL,
    `businessDescription` VARCHAR(191) NULL,
    `businessNiche` VARCHAR(191) NULL,
    `tags` JSON NULL,
    `addedById` INTEGER NOT NULL,
    `callSessionId` INTEGER NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `Sale_clientPhone_idx`(`clientPhone`),
    INDEX `Sale_addedById_idx`(`addedById`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Team` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(191) NOT NULL,
    `description` VARCHAR(191) NULL,
    `supervisorId` INTEGER NOT NULL,
    `madeById` INTEGER NOT NULL,
    `status` VARCHAR(191) NOT NULL DEFAULT 'active',
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `Team_supervisorId_idx`(`supervisorId`),
    INDEX `Team_madeById_idx`(`madeById`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Voicemail` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `callSid` VARCHAR(191) NOT NULL,
    `fromNumber` VARCHAR(191) NOT NULL,
    `toNumber` VARCHAR(191) NOT NULL,
    `recordingSid` VARCHAR(191) NULL,
    `recordingUrl` VARCHAR(191) NULL,
    `transcription` VARCHAR(191) NULL,
    `duration` INTEGER NOT NULL DEFAULT 0,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `listenedAt` DATETIME(3) NULL,
    `userId` INTEGER NOT NULL,

    UNIQUE INDEX `Voicemail_callSid_key`(`callSid`),
    INDEX `Voicemail_userId_idx`(`userId`),
    INDEX `Voicemail_createdAt_idx`(`createdAt`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `LeadLog` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `leadId` INTEGER NOT NULL,
    `action` VARCHAR(191) NOT NULL,
    `message` VARCHAR(191) NULL,
    `oldData` JSON NULL,
    `newData` JSON NULL,
    `userId` INTEGER NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE `LeadRemark` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `leadId` INTEGER NOT NULL,
    `callStatus` ENUM('connected', 'not_connected') NULL DEFAULT 'connected',
    `userId` INTEGER NOT NULL,
    `note` VARCHAR(191) NOT NULL,
    `attachmentUrl` VARCHAR(191) NULL,
    `attachmentType` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE `Disposition` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(191) NOT NULL,
    `color` VARCHAR(191) NOT NULL,
    `sequence` INTEGER NOT NULL DEFAULT 0,
    `status` BOOLEAN NOT NULL DEFAULT true,
    `createdById` INTEGER NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `Disposition_createdById_idx`(`createdById`),
    INDEX `Disposition_status_idx`(`status`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `LiveCall` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `conferenceName` VARCHAR(191) NOT NULL,
    `direction` VARCHAR(191) NOT NULL,
    `customerNumber` VARCHAR(191) NOT NULL,
    `customerName` VARCHAR(191) NULL,
    `agentId` INTEGER NULL,
    `agentName` VARCHAR(191) NULL,
    `isTransfer` BOOLEAN NOT NULL DEFAULT false,
    `startedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `LiveCall_conferenceName_key`(`conferenceName`),
    INDEX `LiveCall_conferenceName_idx`(`conferenceName`),
    INDEX `LiveCall_agentId_idx`(`agentId`),
    INDEX `LiveCall_startedAt_idx`(`startedAt`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Email` (
    `id` VARCHAR(191) NOT NULL,
    `userId` INTEGER NULL,
    `messageId` VARCHAR(191) NULL,
    `from` VARCHAR(191) NOT NULL,
    `to` VARCHAR(191) NOT NULL,
    `cc` VARCHAR(191) NULL,
    `subject` VARCHAR(191) NULL,
    `text` TEXT NULL,
    `html` TEXT NULL,
    `direction` VARCHAR(191) NOT NULL DEFAULT 'inbound',
    `status` VARCHAR(191) NOT NULL DEFAULT 'received',
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

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

-- CreateTable
CREATE TABLE `EmailAttachment` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `emailId` VARCHAR(191) NOT NULL,
    `filename` VARCHAR(191) NOT NULL,
    `contentType` VARCHAR(191) NOT NULL,
    `size` INTEGER NOT NULL,
    `path` VARCHAR(191) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE `TeamPrivilege` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `teamId` INTEGER NOT NULL,
    `supervisorId` INTEGER NOT NULL,
    `viewDashboard` BOOLEAN NOT NULL DEFAULT true,
    `addMembers` BOOLEAN NOT NULL DEFAULT true,
    `listenLiveCalls` BOOLEAN NOT NULL DEFAULT true,
    `viewReports` BOOLEAN NOT NULL DEFAULT true,
    `editTeamSettings` BOOLEAN NOT NULL DEFAULT false,
    `assignQueues` BOOLEAN NOT NULL DEFAULT false,
    `monitorPerformance` BOOLEAN NOT NULL DEFAULT true,
    `manageAgentStatus` BOOLEAN NOT NULL DEFAULT false,
    `bargeCalls` BOOLEAN NOT NULL DEFAULT false,
    `whisperToAgents` BOOLEAN NOT NULL DEFAULT false,
    `canListenRecording` BOOLEAN NOT NULL DEFAULT false,
    `canAddLead` BOOLEAN NOT NULL DEFAULT false,
    `exportData` BOOLEAN NOT NULL DEFAULT false,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `TeamPrivilege_teamId_idx`(`teamId`),
    INDEX `TeamPrivilege_supervisorId_idx`(`supervisorId`),
    UNIQUE INDEX `TeamPrivilege_teamId_key`(`teamId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Role` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(191) NOT NULL,
    `description` VARCHAR(191) NULL,
    `makeCall` BOOLEAN NOT NULL DEFAULT false,
    `showCallDNC` BOOLEAN NOT NULL DEFAULT false,
    `canCallDNC` BOOLEAN NOT NULL DEFAULT false,
    `transcription` BOOLEAN NOT NULL DEFAULT false,
    `transfer` BOOLEAN NOT NULL DEFAULT false,
    `recording` BOOLEAN NOT NULL DEFAULT false,
    `loginIp` BOOLEAN NOT NULL DEFAULT false,
    `loginIpAddress` VARCHAR(191) NULL,
    `mms` BOOLEAN NOT NULL DEFAULT false,
    `twoFA` BOOLEAN NOT NULL DEFAULT false,
    `endCallPop` BOOLEAN NOT NULL DEFAULT false,
    `emailPrivilege` BOOLEAN NOT NULL DEFAULT false,
    `additionalEmail` VARCHAR(191) NULL,
    `targetEnable` BOOLEAN NOT NULL DEFAULT false,
    `targetValue` VARCHAR(191) NULL,
    `viewDashboard` BOOLEAN NOT NULL DEFAULT false,
    `viewTeamDashboard` BOOLEAN NOT NULL DEFAULT false,
    `viewCallLogs` BOOLEAN NOT NULL DEFAULT false,
    `viewContacts` BOOLEAN NOT NULL DEFAULT false,
    `viewMessages` BOOLEAN NOT NULL DEFAULT false,
    `viewEmails` BOOLEAN NOT NULL DEFAULT false,
    `viewLeads` BOOLEAN NOT NULL DEFAULT false,
    `viewSales` BOOLEAN NOT NULL DEFAULT false,
    `viewKpis` BOOLEAN NOT NULL DEFAULT false,
    `viewCompanyContacts` BOOLEAN NOT NULL DEFAULT false,
    `editProfile` BOOLEAN NOT NULL DEFAULT false,
    `changePassword` BOOLEAN NOT NULL DEFAULT false,
    `composeEmail` BOOLEAN NOT NULL DEFAULT false,
    `canMakeChatGroup` BOOLEAN NOT NULL DEFAULT false,
    `canDeleteContact` BOOLEAN NOT NULL DEFAULT false,
    `canEditContact` BOOLEAN NOT NULL DEFAULT false,
    `accessAutoDialAdmin` BOOLEAN NOT NULL DEFAULT false,
    `accessDisposition` BOOLEAN NOT NULL DEFAULT false,
    `teamMessages` BOOLEAN NOT NULL DEFAULT false,
    `teamCalls` BOOLEAN NOT NULL DEFAULT false,
    `viewAdminDashboard` BOOLEAN NOT NULL DEFAULT false,
    `manageAgents` BOOLEAN NOT NULL DEFAULT false,
    `manageTeams` BOOLEAN NOT NULL DEFAULT false,
    `manageNumbers` BOOLEAN NOT NULL DEFAULT false,
    `manageLeadsAdmin` BOOLEAN NOT NULL DEFAULT false,
    `viewCallLogsAdmin` BOOLEAN NOT NULL DEFAULT false,
    `viewReports` BOOLEAN NOT NULL DEFAULT false,
    `manageRoles` BOOLEAN NOT NULL DEFAULT false,
    `manageBilling` BOOLEAN NOT NULL DEFAULT false,
    `liveCallsAccess` BOOLEAN NOT NULL DEFAULT false,
    `manageScripts` BOOLEAN NOT NULL DEFAULT false,
    `viewScript` BOOLEAN NOT NULL DEFAULT false,
    `smsTemplates` BOOLEAN NOT NULL DEFAULT false,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

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

-- CreateTable
CREATE TABLE `CallScript` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `title` VARCHAR(191) NOT NULL,
    `description` VARCHAR(191) NULL,
    `content` LONGTEXT NOT NULL,
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `createdById` 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 `CallScriptAssignment` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `scriptId` INTEGER NOT NULL,
    `userId` INTEGER NOT NULL,
    `assignedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE `SmsTemplate` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `userId` INTEGER NOT NULL,
    `title` VARCHAR(191) NOT NULL,
    `body` LONGTEXT 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 `TeamMember` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `userId` INTEGER NOT NULL,
    `teamId` INTEGER NOT NULL,
    `addedById` INTEGER NULL,
    `addedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `roleInTeam` VARCHAR(191) NULL,

    INDEX `TeamMember_userId_idx`(`userId`),
    INDEX `TeamMember_teamId_idx`(`teamId`),
    UNIQUE INDEX `TeamMember_userId_teamId_key`(`userId`, `teamId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `DNCNumber` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `number` VARCHAR(191) NOT NULL,
    `reason` VARCHAR(191) NULL,
    `markedBy` INTEGER NOT NULL,
    `markedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `DNCNumber_number_key`(`number`),
    INDEX `DNCNumber_number_idx`(`number`),
    INDEX `DNCNumber_markedBy_idx`(`markedBy`),
    INDEX `DNCNumber_markedAt_idx`(`markedAt`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `AutoDialCampaign` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(191) NOT NULL,
    `description` VARCHAR(191) NULL,
    `createdById` INTEGER NOT NULL,
    `enabled` BOOLEAN NOT NULL DEFAULT false,
    `status` VARCHAR(191) NOT NULL DEFAULT 'draft',
    `dialingMode` VARCHAR(191) NOT NULL DEFAULT 'progressive',
    `assignmentRule` VARCHAR(191) NOT NULL DEFAULT 'round_robin',
    `maxRetries` INTEGER NOT NULL DEFAULT 2,
    `retryDelayMinutes` INTEGER NOT NULL DEFAULT 30,
    `callerId` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `AutoDialCampaign_createdById_idx`(`createdById`),
    INDEX `AutoDialCampaign_enabled_idx`(`enabled`),
    INDEX `AutoDialCampaign_status_idx`(`status`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `AutoDialCampaignAgent` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `campaignId` INTEGER NOT NULL,
    `agentId` INTEGER NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `AutoDialCampaignAgent_campaignId_idx`(`campaignId`),
    INDEX `AutoDialCampaignAgent_agentId_idx`(`agentId`),
    UNIQUE INDEX `AutoDialCampaignAgent_campaignId_agentId_key`(`campaignId`, `agentId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `AutoDialQueue` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `campaignId` INTEGER NOT NULL,
    `contactId` INTEGER NULL,
    `contactPhoneId` INTEGER NULL,
    `phoneNumber` VARCHAR(191) NOT NULL,
    `assignedAgentId` INTEGER NULL,
    `assignedById` INTEGER NULL,
    `status` VARCHAR(191) NOT NULL DEFAULT 'pending',
    `priority` INTEGER NOT NULL DEFAULT 0,
    `attempts` INTEGER NOT NULL DEFAULT 0,
    `maxRetries` INTEGER NOT NULL DEFAULT 2,
    `nextAttemptAt` DATETIME(3) NULL,
    `lastCallSessionId` INTEGER NULL,
    `lastCallSid` VARCHAR(191) NULL,
    `lastError` VARCHAR(191) NULL,
    `reservedAt` DATETIME(3) NULL,
    `reservedBy` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `AutoDialQueue_campaignId_idx`(`campaignId`),
    INDEX `AutoDialQueue_assignedAgentId_idx`(`assignedAgentId`),
    INDEX `AutoDialQueue_status_idx`(`status`),
    INDEX `AutoDialQueue_phoneNumber_idx`(`phoneNumber`),
    INDEX `AutoDialQueue_nextAttemptAt_idx`(`nextAttemptAt`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `AutoDialAttempt` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `queueId` INTEGER NOT NULL,
    `agentId` INTEGER NULL,
    `callSessionId` INTEGER NULL,
    `callSid` VARCHAR(191) NULL,
    `status` VARCHAR(191) NOT NULL,
    `startedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `connectedAt` DATETIME(3) NULL,
    `endedAt` DATETIME(3) NULL,
    `duration` INTEGER NULL,
    `errorMessage` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `AutoDialAttempt_queueId_idx`(`queueId`),
    INDEX `AutoDialAttempt_agentId_idx`(`agentId`),
    INDEX `AutoDialAttempt_callSessionId_idx`(`callSessionId`),
    INDEX `AutoDialAttempt_status_idx`(`status`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Company` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(191) NOT NULL,
    `slug` VARCHAR(191) NOT NULL,
    `email` VARCHAR(191) NOT NULL,
    `phone` VARCHAR(191) NULL,
    `address` VARCHAR(191) NULL,
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `Company_slug_key`(`slug`),
    UNIQUE INDEX `Company_email_key`(`email`),
    INDEX `Company_slug_idx`(`slug`),
    INDEX `Company_isActive_idx`(`isActive`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CompanyWallet` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `companyId` INTEGER NOT NULL,
    `balance` DOUBLE NOT NULL DEFAULT 0.0,
    `freeBalance` DOUBLE NOT NULL DEFAULT 0.0,
    `currency` VARCHAR(191) NOT NULL DEFAULT 'USD',
    `negativeLimit` DOUBLE NOT NULL DEFAULT -5.0,
    `maxOutboundMinutes` INTEGER NULL,
    `maxOutboundSms` INTEGER NULL,
    `maxOutboundMms` INTEGER NULL,
    `usedOutboundMinutes` DOUBLE NOT NULL DEFAULT 0,
    `usedOutboundSms` INTEGER NOT NULL DEFAULT 0,
    `usedOutboundMms` INTEGER NOT NULL DEFAULT 0,
    `isFrozen` BOOLEAN NOT NULL DEFAULT false,
    `frozenAt` DATETIME(3) NULL,
    `lastTopupAt` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `CompanyWallet_companyId_key`(`companyId`),
    INDEX `CompanyWallet_companyId_idx`(`companyId`),
    INDEX `CompanyWallet_isFrozen_idx`(`isFrozen`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `WalletTransaction` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `companyId` INTEGER NOT NULL,
    `type` VARCHAR(191) NOT NULL,
    `amount` DOUBLE NOT NULL,
    `balanceBefore` DOUBLE NOT NULL,
    `balanceAfter` DOUBLE NOT NULL,
    `callSessionId` INTEGER NULL,
    `callSid` VARCHAR(191) NULL,
    `messageId` VARCHAR(191) NULL,
    `twilioCallDuration` DOUBLE NULL,
    `twilioCallCost` DOUBLE NULL,
    `twilioRecordingCost` DOUBLE NULL,
    `twilioTranscriptionCost` DOUBLE NULL,
    `twilioSmsCost` DOUBLE NULL,
    `description` VARCHAR(191) NULL,
    `meta` JSON NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `WalletTransaction_companyId_idx`(`companyId`),
    INDEX `WalletTransaction_type_idx`(`type`),
    INDEX `WalletTransaction_createdAt_idx`(`createdAt`),
    INDEX `WalletTransaction_callSessionId_idx`(`callSessionId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `StripePayment` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `companyId` INTEGER NOT NULL,
    `stripePaymentIntentId` VARCHAR(191) NOT NULL,
    `stripeChargeId` VARCHAR(191) NULL,
    `amount` DOUBLE NOT NULL,
    `currency` VARCHAR(191) NOT NULL DEFAULT 'USD',
    `status` VARCHAR(191) NOT NULL DEFAULT 'pending',
    `walletCredited` BOOLEAN NOT NULL DEFAULT false,
    `walletCreditedAt` DATETIME(3) NULL,
    `metadata` JSON NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `StripePayment_stripePaymentIntentId_key`(`stripePaymentIntentId`),
    INDEX `StripePayment_companyId_idx`(`companyId`),
    INDEX `StripePayment_status_idx`(`status`),
    INDEX `StripePayment_stripePaymentIntentId_idx`(`stripePaymentIntentId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateIndex
CREATE INDEX `CallSession_conferenceName_idx` ON `CallSession`(`conferenceName`);

-- CreateIndex
CREATE UNIQUE INDEX `User_sipIdentity_key` ON `User`(`sipIdentity`);

-- AddForeignKey
ALTER TABLE `User` ADD CONSTRAINT `User_additionalRoleId_fkey` FOREIGN KEY (`additionalRoleId`) REFERENCES `Role`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

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

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

-- AddForeignKey
ALTER TABLE `CallTranscript` ADD CONSTRAINT `CallTranscript_callSessionId_fkey` FOREIGN KEY (`callSessionId`) REFERENCES `CallSession`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

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

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

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

-- AddForeignKey
ALTER TABLE `Lead` ADD CONSTRAINT `Lead_dispositionId_fkey` FOREIGN KEY (`dispositionId`) REFERENCES `Disposition`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Lead` ADD CONSTRAINT `Lead_addedById_fkey` FOREIGN KEY (`addedById`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Lead` ADD CONSTRAINT `Lead_callSessionId_fkey` FOREIGN KEY (`callSessionId`) REFERENCES `CallSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Sale` ADD CONSTRAINT `Sale_addedById_fkey` FOREIGN KEY (`addedById`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Sale` ADD CONSTRAINT `Sale_callSessionId_fkey` FOREIGN KEY (`callSessionId`) REFERENCES `CallSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Team` ADD CONSTRAINT `Team_supervisorId_fkey` FOREIGN KEY (`supervisorId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Team` ADD CONSTRAINT `Team_madeById_fkey` FOREIGN KEY (`madeById`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE `LeadLog` ADD CONSTRAINT `LeadLog_leadId_fkey` FOREIGN KEY (`leadId`) REFERENCES `Lead`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE `LeadRemark` ADD CONSTRAINT `LeadRemark_leadId_fkey` FOREIGN KEY (`leadId`) REFERENCES `Lead`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE `Disposition` ADD CONSTRAINT `Disposition_createdById_fkey` FOREIGN KEY (`createdById`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `LiveCall` ADD CONSTRAINT `LiveCall_agentId_fkey` FOREIGN KEY (`agentId`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Email` ADD CONSTRAINT `Email_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EmailAttachment` ADD CONSTRAINT `EmailAttachment_emailId_fkey` FOREIGN KEY (`emailId`) REFERENCES `Email`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `TeamPrivilege` ADD CONSTRAINT `TeamPrivilege_teamId_fkey` FOREIGN KEY (`teamId`) REFERENCES `Team`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `TeamPrivilege` ADD CONSTRAINT `TeamPrivilege_supervisorId_fkey` FOREIGN KEY (`supervisorId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CallScript` ADD CONSTRAINT `CallScript_createdById_fkey` FOREIGN KEY (`createdById`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CallScriptAssignment` ADD CONSTRAINT `CallScriptAssignment_scriptId_fkey` FOREIGN KEY (`scriptId`) REFERENCES `CallScript`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

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

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

-- AddForeignKey
ALTER TABLE `TeamMember` ADD CONSTRAINT `TeamMember_teamId_fkey` FOREIGN KEY (`teamId`) REFERENCES `Team`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `TeamMember` ADD CONSTRAINT `TeamMember_addedById_fkey` FOREIGN KEY (`addedById`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DNCNumber` ADD CONSTRAINT `DNCNumber_markedBy_fkey` FOREIGN KEY (`markedBy`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialCampaign` ADD CONSTRAINT `AutoDialCampaign_createdById_fkey` FOREIGN KEY (`createdById`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialCampaignAgent` ADD CONSTRAINT `AutoDialCampaignAgent_campaignId_fkey` FOREIGN KEY (`campaignId`) REFERENCES `AutoDialCampaign`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialCampaignAgent` ADD CONSTRAINT `AutoDialCampaignAgent_agentId_fkey` FOREIGN KEY (`agentId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialQueue` ADD CONSTRAINT `AutoDialQueue_campaignId_fkey` FOREIGN KEY (`campaignId`) REFERENCES `AutoDialCampaign`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialQueue` ADD CONSTRAINT `AutoDialQueue_contactId_fkey` FOREIGN KEY (`contactId`) REFERENCES `Contact`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialQueue` ADD CONSTRAINT `AutoDialQueue_contactPhoneId_fkey` FOREIGN KEY (`contactPhoneId`) REFERENCES `ContactPhone`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialQueue` ADD CONSTRAINT `AutoDialQueue_assignedAgentId_fkey` FOREIGN KEY (`assignedAgentId`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialQueue` ADD CONSTRAINT `AutoDialQueue_assignedById_fkey` FOREIGN KEY (`assignedById`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialQueue` ADD CONSTRAINT `AutoDialQueue_lastCallSessionId_fkey` FOREIGN KEY (`lastCallSessionId`) REFERENCES `CallSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialAttempt` ADD CONSTRAINT `AutoDialAttempt_queueId_fkey` FOREIGN KEY (`queueId`) REFERENCES `AutoDialQueue`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialAttempt` ADD CONSTRAINT `AutoDialAttempt_agentId_fkey` FOREIGN KEY (`agentId`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AutoDialAttempt` ADD CONSTRAINT `AutoDialAttempt_callSessionId_fkey` FOREIGN KEY (`callSessionId`) REFERENCES `CallSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

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

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

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