module.exports = (sequelize, DataTypes) => {
  const PaymentHistory = sequelize.define(
    "PaymentHistory",
    {
      payment_id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      student_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: "students",
          key: "id",
        },
      },
      fee_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: "Fees",
          key: "fee_id",
        },
      },
      payment_amount: {
        type: DataTypes.DECIMAL(10, 2),
        allowNull: false,
      },
      payment_date: {
        type: DataTypes.DATEONLY,
        allowNull: false,
      },
      payment_method: {
        type: DataTypes.STRING(20),
        allowNull: false,
      },
      month: {
        type: DataTypes.STRING(20),
        allowNull: false,
      },
      isActive: {
        type: DataTypes.INTEGER,
        allowNull: true,
        defaultValue: 1,
      },
    },
    {
      tableName: "PaymentHistory",
      timestamps: false,
    }
  );

  PaymentHistory.associate = (models) => {
    PaymentHistory.belongsTo(models.Fee, { foreignKey: "fee_id" });
    PaymentHistory.belongsTo(models.Student, { foreignKey: "student_id" });
  };

  return PaymentHistory;
};
