import { DataTypes } from "sequelize";
import { sequelize } from "@/configs/sequelize";
import { User } from "./user";
import { Disease } from "./disease";

export const Rule = sequelize.define(
    "Rule",
    {
        id: {
            type: DataTypes.UUID,
            primaryKey: true,
            defaultValue: DataTypes.UUIDV4,
        },
        disease_id: {
            type: DataTypes.UUID,
            allowNull: false,
        },
        confidence: {
            type: DataTypes.INTEGER,
            defaultValue: 0,
        },
        symptoms_id: {
            type: DataTypes.JSON,
            allowNull: false,
        },
        follow_up_questions: {
            type: DataTypes.JSON,
            defaultValue: [],
        },
        created_by_id: {
            type: DataTypes.UUID,
            allowNull: false,
        },
    },
    {
        tableName: "rules",
        timestamps: true,
        createdAt: "created_at",
        updatedAt: "updated_at",
    },
);

Rule.belongsTo(User, {
    foreignKey: "created_by_id",
    as: "created_by",
});

Rule.belongsTo(Disease, {
    foreignKey: "disease_id",
    as: "disease",
});
