const { DataTypes } = require("sequelize");
const sequelize = require("../db");

const HazopAction = sequelize.define("HazopAction", {
  data: {
    type: DataTypes.JSON,
    allowNull: false,
    defaultValue: {},
  },
  status: {
    type: DataTypes.ENUM("open", "in-progress", "closed", "cancelled"),
    allowNull: false,
    defaultValue: "open",
  },
  dueDate: {
    type: DataTypes.DATEONLY,
    allowNull: false,
  },
  closedAt: {
    type: DataTypes.DATEONLY,
    allowNull: true,
  },
  HazopStudyId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: "HazopStudies",
      key: "id",
    },
  },
  ownerId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: "Users",
      key: "id",
    },
  },
  closedById: {
    type: DataTypes.INTEGER,
    allowNull: true,
    references: {
      model: "Users",
      key: "id",
    },
  },
});

module.exports = HazopAction;
