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

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

      invoice_no: { type: DataTypes.STRING, allowNull: false },
      tax_invoice_no: { type: DataTypes.STRING, allowNull: true },
      invoice_date: { type: DataTypes.DATE, allowNull: true },
      amount: { type: DataTypes.INTEGER, allowNull: true },
      due_date: { type: DataTypes.DATE, allowNull: true },

      //fk
      invoicereceipt_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: "invoicereceipts",
          key: "id",
        },
      },

    },
    {
      tableName: "invoicereceiptchilds",
      freezeTableName: true,
    }
  );

  /**
   * Associates the InvoiceReceiptChild model with other models.
   * @param {object} models - The models to associate with.
   * @description
   *   - A InvoiceReceiptChild belongs to a InvoiceReceipt.
   */
  InvoiceReceiptChild.associate = (models) => {
    /**
     * Associates the InvoiceReceiptChild model with the InvoiceReceipt model.
     * A InvoiceReceiptChild belongs to a InvoiceReceipt.
     * @param {object} models - The models to associate with.
     */
   InvoiceReceiptChild.belongsTo(models.InvoiceReceipt, {
      foreignKey: "invoicereceipt_id",
      as: "invoicereceipt",
    });
  };

  return InvoiceReceiptChild;
};
