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

module.exports = (sequelize) => {
  const NCProductFU = sequelize.define(
    "ncproductfu",
    {
      id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      creation: { type: DataTypes.DATE, allowNull: false },
      modified: { type: DataTypes.DATE, allowNull: false },
      modified_by: { type: DataTypes.INTEGER, allowNull: false },
      owner: { type: DataTypes.INTEGER, allowNull: false },
      enabled: { type: DataTypes.BOOLEAN, allowNull: false },

      date: { type: DataTypes.DATE, allowNull: true },
      description: { type: DataTypes.TEXT, allowNull: true },
      pic_id: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: {
          model: "employees",
          key: "id",
        },
      },

      //fk
      ncproduct_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: "ncproducts",
          key: "id",
        },
      },
    },
    {
      tableName: "ncproductfus",
      freezeTableName: true,
    }
  );

  NCProductFU.associate = (models) => {
    NCProductFU.belongsTo(models.NcProduct, {
      foreignKey: "ncproduct_id",
      as: "ncproduct",
    });

    NCProductFU.belongsTo(models.Employee, {
      foreignKey: "pic_id",
      as: "employee",
    });
  };

  return NCProductFU;
};
