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

const ExerciseModel = (DataTypes) => {
  const Exercises = db.define(
    "admin_exercise",
    {
      ID_ADMIN_EXERCISE: {
        type: DataTypes.UUID,
        primaryKey: true,
        defaultValue: DataTypes.UUIDV4,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
      },
      ID_LEVEL: {
        type: DataTypes.UUID,
        allowNull: false,
        references: {
          model: "level",
          key: "ID_LEVEL",
        },
        validate: {
          notEmpty: true,
        },
      },
      TITLE: {
        type: DataTypes.STRING(100),
        allowNull: false,
        validate: {
          notEmpty: true,
        },
      },
      QUESTION: {
        type: DataTypes.TEXT,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
      },
      SCORE_WEIGHT: {
        type: DataTypes.INTEGER(11),
        allowNull: false,
        defaultValue: 1,
        validate: {
          notEmpty: true,
        },
      },
      QUESTION_TYPE: {
        type: DataTypes.TEXT,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
      },
      AUDIO: {
        type: DataTypes.STRING(1024),
        allowNull: true,
      },
      VIDEO: {
        type: DataTypes.STRING(1024),
        allowNull: true,
      },
      IMAGE: {
        type: DataTypes.STRING(1024),
        allowNull: true,
      },
      IS_DELETED: {
        type: DataTypes.TINYINT(1),
        allowNull: true,
        defaultValue: 0,
        validate: {
          min: 0,
          max: 1,
        },
      },
      TIME_ADMIN_EXC: {
        type: DataTypes.DATE,
        allowNull: true,
        defaultValue: DataTypes.NOW,
      },
    },
    {
      timestamps: false,
      tableName: "admin_exercise",
    }
  );

  return Exercises;
};

export default ExerciseModel;
