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

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


      name: { type: DataTypes.STRING(100), allowNull: false },
      department: { type: DataTypes.STRING(250), allowNull: true },
      contact: { type: DataTypes.STRING(100), allowNull: false },
      email: { type: DataTypes.STRING(100), allowNull: false },

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

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

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

  return CustomerPICChild;
};
