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

const LevelModel = (DataTypes) => {
  const Levels = db.define(
    "level",
    {
      ID_LEVEL: {
        type: DataTypes.UUID,
        primaryKey: true,
        defaultValue: DataTypes.UUIDV4,
        validate: {
          notEmpty: true,
        },
      },
      ID_TOPIC: {
        type: DataTypes.UUID,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
        references: {
          model: "topic",
          key: "ID_TOPIC",
        },
      },
      ID_SECTION: {
        type: DataTypes.UUID,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
        references: {
          model: "section",
          key: "ID_SECTION",
        },
      },
      NAME_LEVEL: {
        type: DataTypes.STRING(100),
        allowNull: false,
        validate: {
          notEmpty: true,
        },
      },
      CONTENT: {
        type: DataTypes.TEXT('long'),
        allowNull: true,
      },
      AUDIO: {
        type: DataTypes.STRING(1024),
        allowNull: true,
      },
      IMAGE: {
        type: DataTypes.STRING(1024),
        allowNull: true,
      },
      VIDEO: {
        type: DataTypes.STRING(1024),
        allowNull: true,
      },
      IS_PRETEST: {
        type: DataTypes.TINYINT(1),
        allowNull: true,
        defaultValue: 0,
        validate: {
          min: 0,
          max: 1,
        },
      },
      ROUTE_1: {
        type: DataTypes.UUID,
        allowNull: false,
      },
      ROUTE_2: {
        type: DataTypes.UUID,
        allowNull: false,
      },
      ROUTE_3: {
        type: DataTypes.UUID,
        allowNull: false,
      },
      ROUTE_4: {
        type: DataTypes.UUID,
        allowNull: false,
      },
      ROUTE_5: {
        type: DataTypes.UUID,
        allowNull: false,
      },
      ROUTE_6: {
        type: DataTypes.UUID,
        allowNull: false,
      },
      IS_DELETED: {
        type: DataTypes.TINYINT(1),
        allowNull: true,
        defaultValue: 0,
        validate: {
          min: 0,
          max: 1,
        },
      },
      TIME_LEVEL: {
        type: DataTypes.DATE,
        allowNull: true,
        defaultValue: DataTypes.NOW,
      },
    },
    {
      timestamps: false,
      tableName: "level",
    }
  );
  return Levels;
};

export default LevelModel;
