import db from "../../database/db.js";

const TopicModel = (DataTypes) => {
  const Topics = db.define(
    "topic",
    {
      ID_TOPIC: {
        type: DataTypes.UUID,
        primaryKey: true,
        defaultValue: DataTypes.UUIDV4,
        validate: {
          notEmpty: true,
        },
      },
      ID_SECTION: {
        type: DataTypes.UUID,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
        references: {
          model: "section",
          key: "ID_SECTION",
        },
      },
      NAME_TOPIC: {
        type: DataTypes.STRING(100),
        allowNull: false,
        validate: {
          notEmpty: true,
        },
      },
      DESCRIPTION_TOPIC: {
        type: DataTypes.TEXT,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
      },
      IS_DELETED: {
        type: DataTypes.TINYINT(1),
        allowNull: true,
        defaultValue: 0,
        validate: {
          min: 0,
          max: 1,
        },
      },
      TIME_TOPIC: {
        type: DataTypes.DATE,
        allowNull: true,
        defaultValue: DataTypes.NOW,
      },
    },
    {
      timestamps: false, 
      tableName: "topic", 
    }
  );
  return Topics;
};

export default TopicModel;
