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

module.exports = {
  async up(queryInterface) {
    await queryInterface.createTable("level", {
      ID_LEVEL: {
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: Sequelize.UUIDV4,
        allowNull: false,
      },
      ID_TOPIC: {
        type: Sequelize.UUID,
        allowNull: false,
      },
      ID_SECTION: {
        type: Sequelize.UUID,
        allowNull: false,
      },
      NAME_LEVEL: {
        type: Sequelize.STRING(100),
        allowNull: false,
      },
      CONTENT: {
        type: Sequelize.TEXT('long'),
        allowNull: true,
      },
      AUDIO: {
        type: Sequelize.STRING(1024),
        allowNull: true,
      },
      IMAGE: {
        type: Sequelize.STRING(1024),
        allowNull: true,
      },
      VIDEO: {
        type: Sequelize.STRING(1024),
        allowNull: true,
      },
      IS_PRETEST: {
        type: Sequelize.TINYINT(1),
        allowNull: true,
        defaultValue: 0,
      },
      ROUTE_1: {
        type: Sequelize.UUID,
        allowNull: false,
        defaultValue: 0,
      },
      ROUTE_2: {
        type: Sequelize.UUID,
        allowNull: false,
        defaultValue: 0,
      },
      ROUTE_3: {
        type: Sequelize.UUID,
        allowNull: false,
        defaultValue: 0,
      },
      ROUTE_4: {
        type: Sequelize.UUID,
        allowNull: false,
        defaultValue: 0,
      },
      ROUTE_5: {
        type: Sequelize.UUID,
        allowNull: false,
        defaultValue: 0,
      },
      ROUTE_6: {
        type: Sequelize.UUID,
        allowNull: false,
        defaultValue: 0,
      },
      IS_DELETED: {
        type: Sequelize.TINYINT(1),
        allowNull: true,
        defaultValue: 0,
      },
      TIME_LEVEL: {
        type: Sequelize.DATE,
        allowNull: true,
        defaultValue: Sequelize.NOW,
      },
    });

    await queryInterface.addConstraint("level", {
      fields: ["ID_TOPIC"],
      type: "foreign key",
      name: "FK_BERHUBUNGAN",
      references: {
        table: "topic",
        field: "ID_TOPIC",
      },
      onUpdate: "CASCADE",
      onDelete: "CASCADE",
    });

    await queryInterface.addConstraint("level", {
      fields: ["ID_SECTION"],
      type: "foreign key",
      name: "FK_MEMPUNYAI",
      references: {
        table: "section",
        field: "ID_SECTION",
      },
      onUpdate: "CASCADE",
      onDelete: "CASCADE",
    });
  },

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