const { Sequelize } = require("sequelize");

module.exports = {
  async up(queryInterface) {
    await queryInterface.createTable("monitoring", {
      ID_MONITORING: {
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: Sequelize.UUIDV4,
        allowNull: false,
      },
      ID_STUDENT_LEARNING: {
        type: Sequelize.UUID,
        allowNull: false,
      },
      ID_CLASS: {
        type: Sequelize.UUID,
        allowNull: true,
      },
      ID_GURU: {
        type: Sequelize.UUID,
        allowNull: true,
      },
      FEEDBACK_GURU: {
        type: Sequelize.TEXT,
        allowNull: true,
      },
      TIME_MONITORING: {
        type: Sequelize.DATE,
        allowNull: true,
        defaultValue: Sequelize.NOW,
      },
    });

    await queryInterface.addConstraint("monitoring", {
      fields: ["ID_STUDENT_LEARNING"],
      type: "foreign key",
      name: "FK_MENGACU",
      references: {
        table: "student_learning",
        field: "ID_STUDENT_LEARNING",
      },
      onUpdate: "CASCADE",
      onDelete: "CASCADE",
    });

    await queryInterface.addConstraint("monitoring", {
      fields: ["ID_CLASS"],
      type: "foreign key",
      name: "FK_MENDAPATKAN",
      references: {
        table: "class",
        field: "ID_CLASS",
      },
      onUpdate: "CASCADE",
      onDelete: "SET NULL",
    });

    await queryInterface.addConstraint("monitoring", {
      fields: ["ID_GURU"],
      type: "foreign key",
      name: "FK_DILAKUKAN",
      references: {
        table: "teacher",
        field: "ID_GURU",
      },
      onUpdate: "CASCADE",
      onDelete: "SET NULL",
    });
  },

  async down(queryInterface) {
    await queryInterface.dropTable("monitoring");
  },
};