module.exports = (sequelize, DataTypes) => {
  const BookingAdditionalPayments = sequelize.define(
    'BookingAdditionalPayments',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
        allowNull: false,
      },
      booking_id: {
        type: DataTypes.UUID,
        allowNull: true,
        references: {
          model: 'bookings',
          key: 'id',
        },
        onDelete: 'SET NULL',
      },
      description: {
        type: DataTypes.STRING,
        allowNull: true,
      },
      status: {
        type: DataTypes.ENUM('Unpaid', 'Paid', 'Failed'),
        allowNull: false,
        defaultValue: 'Unpaid',
      },
      amount_paid: {
        type: DataTypes.DECIMAL(10, 2),
        allowNull: false,
        defaultValue: 0.0,
      },
      payment_intent_id: {
        type: DataTypes.STRING,
        allowNull: true,
      },
      paymongo_payment_id: {
        type: DataTypes.STRING,
        allowNull: true,
      },
      payment_method: {
        type: DataTypes.STRING,
        allowNull: true,
      },
      paymongo_fee: {
        type: DataTypes.DECIMAL(10, 2),
        allowNull: true,
        defaultValue: 0.0,
      },
      is_refunded: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: false,
      },
      refund_amount: {
        type: DataTypes.DECIMAL(10, 2),
        allowNull: true,
        defaultValue: 0.0,
      },
      createdAt: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
      },
      updatedAt: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
      },
    },
    {
      tableName: 'booking_additional_payments',
      timestamps: true,
    },
  );

  BookingAdditionalPayments.associate = (models) => {
    BookingAdditionalPayments.belongsTo(models.Bookings, {
      foreignKey: 'booking_id',
      as: 'booking',
    });
  };

  return BookingAdditionalPayments;
};
