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

const StdLearningModel = (DataTypes) => {
  const StdLearning = db.define(
    "student_learning",
    {
      ID_STUDENT_LEARNING: {
        type: DataTypes.UUID,
        primaryKey: true,
        defaultValue: DataTypes.UUIDV4,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
      },
      ID: {
        type: DataTypes.UUID,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
        references: {
          model: "users",
          key: "ID",
        },
      },
      ID_LEVEL: {
        type: DataTypes.UUID,
        allowNull: false,
        validate: {
          notEmpty: true,
        },
        references: {
          model: "level",
          key: "ID_LEVEL",
        },
      },
      STUDENT_START: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: DataTypes.NOW,
      },
      STUDENT_FINISH: {
        type: DataTypes.DATE,
        allowNull: true,
        defaultValue: null,
      },
      SCORE: {
        type: DataTypes.INTEGER(11),
        allowNull: true,
        defaultValue: null,
      },
      IS_PASS: {
        type: DataTypes.TINYINT(1),
        allowNull: false,
        defaultValue: 0,
        validate: {
          min: 0,
          max: 1,
        },
      },
      NEXT_LEARNING: {
        type: DataTypes.UUID,
        allowNull: true,
        defaultValue: null,
        references: {
          model: "level",
          key: "ID_LEVEL",
        },
      },
      FEEDBACK_STUDENT: {
        type: DataTypes.TEXT,
        allowNull: true,
        defaultValue: null,
      },
      TIME_LEARNING: {
        type: DataTypes.DATE,
        allowNull: true,
        defaultValue: DataTypes.NOW,
        onUpdate: DataTypes.NOW,
      },
    },
    {
      timestamps: false,
      tableName: "student_learning",
    }
  );

  return StdLearning;
};

export default StdLearningModel;
