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

module.exports = (sequelize) => {
  const ProcurementTrackerItemPO = sequelize.define(
    "procurmenttrackeritempo",
    {
      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 },

      procurementtrackerpo_id: { type: DataTypes.INTEGER, allowNull: true },
      item_name: { type: DataTypes.STRING(250), allowNull: true },
      item_code: { type: DataTypes.STRING(250), allowNull: true },
      quantity: { type: DataTypes.INTEGER, allowNull: true },
      uom: { type: DataTypes.STRING(250), allowNull: true },
    },
    {
      tableName: "procurmenttrackeritempos",
      freezeTableName: true,
    }
  );

  /**
   * Associates the ProcurementTrackerAWB model with other models.
   * @param {object} models - The models to associate with.
   */
  ProcurementTrackerItemPO.associate = (models) => {
    /**
     * Associates the Province model with the City model.
     * Defines a one-to-many relationship between Province and City.
     * @param {object} models - The models to associate with.
     */
    ProcurementTrackerItemPO.belongsTo(models.ProcurementTrackerPO, {
      foreignKey: "procurementtrackerpo_id",
      onDelete: "CASCADE",
    });
  };

  return ProcurementTrackerItemPO;
};
