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

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

      procurementtracker_id: { type: DataTypes.INTEGER, allowNull: true },
      no_invoice: { type: DataTypes.STRING(250), allowNull: true },
      invoice_date: { type: DataTypes.DATE, allowNull: true },
    },
    {
      tableName: "procurementtrackerinvoices",
      freezeTableName: true,
    }
  );

  /**
   * Associates the ProcurementTrackerAWB model with other models.
   * @param {object} models - The models to associate with.
   */
  ProcurementTrackerInvoice.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.
     */
    ProcurementTrackerInvoice.belongsTo(models.ProcurementTracker, {
      foreignKey: "procurementtracker_id",
      onDelete: "CASCADE",
    });
  };

  return ProcurementTrackerInvoice;
};
