CREATE TABLE `AIInsightAction` (
    `Id` int(11) NOT NULL,
    `IsDeleted` int(11),
    `Name` varchar(255),
    `CreatedDate` varchar(255),
    `CreatedById` int(11), -- foreign key: User.Id,
    `LastModifiedDate` varchar(255),
    `LastModifiedById` int(11), -- foreign key: User.Id,
    `SystemModstamp` varchar(255),
    `AiRecordInsightId` int(11), -- foreign key: AIRecordInsight.Id,
    `Type` varchar(255),
    `Confidence` varchar(255),
    `ActionName` varchar(255),
    `ActionId` int(11), -- foreign key: Macro.Id,
    PRIMARY KEY (`Id`) ,
    CONSTRAINT `FK_AIInsightAction_CreatedById` FOREIGN KEY (`CreatedById`) REFERENCES `User` (`Id`),
    CONSTRAINT `FK_AIInsightAction_LastModifiedById` FOREIGN KEY (`LastModifiedById`) REFERENCES `User` (`Id`),
    CONSTRAINT `FK_AIInsightAction_AiRecordInsightId` FOREIGN KEY (`AiRecordInsightId`) REFERENCES `AIRecordInsight` (`Id`),
    CONSTRAINT `FK_AIInsightAction_ActionId` FOREIGN KEY (`ActionId`) REFERENCES `Macro` (`Id`)
);
CREATE TABLE `AIInsightFeedback` (
    `Id` int(11) NOT NULL,
    `IsDeleted` int(11),
    `Name` varchar(255),
    `CreatedDate` varchar(255),
    `CreatedById` int(11), -- foreign key: User.Id,
    `LastModifiedDate` varchar(255),
    `LastModifiedById` int(11), -- foreign key: User.Id,
    `SystemModstamp` varchar(255),
    `AiRecordInsightId` int(11), -- foreign key: AIRecordInsight.Id,
    `AiInsightFeedbackType` varchar(255),
    `AiFeedback` varchar(255),
    `Rank` int(11),
    `ValueId` int(11), -- foreign key: AIInsightValue.Id,
    `ActualValue` varchar(255),
    PRIMARY KEY (`Id`) ,
    CONSTRAINT `FK_AIInsightFeedback_CreatedById` FOREIGN KEY (`CreatedById`) REFERENCES `User` (`Id`),
    CONSTRAINT `FK_AIInsightFeedback_LastModifiedById` FOREIGN KEY (`LastModifiedById`) REFERENCES `User` (`Id`),
    CONSTRAINT `FK_AIInsightFeedback_AiRecordInsightId` FOREIGN KEY (`AiRecordInsightId`) REFERENCES `AIRecordInsight` (`Id`),
    CONSTRAINT `FK_AIInsightFeedback_ValueId` FOREIGN KEY (`ValueId`) REFERENCES `AIInsightValue` (`Id`)
);
CREATE TABLE `AIInsightReason` (
    `Id` int(11) NOT NULL,
    `IsDeleted` int(11),
    `Name` varchar(255),
    `CreatedDate` varchar(255),
    `CreatedById` int(11), -- foreign key: User.Id,
    `LastModifiedDate` varchar(255),
    `LastModifiedById` int(11), -- foreign key: User.Id,
    `SystemModstamp` varchar(255),
    `AiInsightValueId` int(11), -- foreign key: AIInsightValue.Id,
    `Intensity` varchar(255),
    `Contribution` varchar(255),
    `Variance` varchar(255),
    `FieldName` varchar(255),
    `Operator` varchar(255),
    `FieldValue` varchar(255),
    `FeatureValue` varchar(255),
    `FeatureType` varchar(255),
    `RelatedInsightReasonId` int(11), -- foreign key: AIInsightReason.Id,
    `SortOrder` int(11),
    `ReasonLabelKey` varchar(255),
    PRIMARY KEY (`Id`) ,
    CONSTRAINT `FK_AIInsightReason_CreatedById` FOREIGN KEY (`CreatedById`) REFERENCES `User` (`Id`),
    CONSTRAINT `FK_AIInsightReason_LastModifiedById` FOREIGN KEY (`LastModifiedById`) REFERENCES `User` (`Id`),
    CONSTRAINT `FK_AIInsightReason_AiInsightValueId` FOREIGN KEY (`AiInsightValueId`) REFERENCES `AIInsightValue` (`Id`),
    CONSTRAINT `FK_AIInsightReason_RelatedInsightReasonId` FOREIGN KEY (`RelatedInsightReasonId`) REFERENCES `AIInsightReason` (`Id`)
);
CREATE TABLE `AIInsightValue` (
    `Id` int(11) NOT NULL,
    `IsDeleted` int(11),
    `Name` varchar(255),
    `CreatedDate` varchar(255),
    `CreatedById` int(11), -- foreign key: User.Id,
    `LastModifiedDate` varchar(255),
    `LastModifiedById` int(11), -- foreign key: User.Id,
    `SystemModstamp` varchar(255),
    `AiRecordInsightId` int(11), -- foreign key: AIRecordInsight.Id,
    `AiInsightActionId` int(11), -- foreign key: AIInsightAction.Id,
    `ValueType` varchar(255),
    `SobjectType` varchar(255),
    `Field` varchar(255),
    `Value` text,
    `FieldValueLowerBound` text,
    `FieldValueUpperBound` text,
    `Confidence` varchar(255),
    `SobjectLookupValueId` int(11), -- foreign key: WorkThanks.Id,
    PRIMARY KEY (`Id`) ,
    CONSTRAINT `FK_AIInsightValue_CreatedById` FOREIGN KEY (`CreatedById`) REFERENCES `User` (`Id`),
    CONSTRAINT `FK_AIInsightValue_LastModifiedById` FOREIGN KEY (`LastModifiedById`) REFERENCES `User` (`Id`),
    CONSTRAINT `FK_AIInsightValue_AiRecordInsightId` FOREIGN KEY (`AiRecordInsightId`) REFERENCES `AIRecordInsight` (`Id`),
    CONSTRAINT `FK_AIInsightValue_AiInsightActionId` FOREIGN KEY (`AiInsightActionId`) REFERENCES `AIInsightAction` (`Id`),
    CONSTRAINT `FK_AIInsightValue_SobjectLookupValueId` FOREIGN KEY (`SobjectLookupValueId`) REFERENCES `WorkThanks` (`Id`)
);
