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

module.exports = (sequelize) => {
	const ActivityBookings = sequelize.define(
		'ActivityBookings',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			reference_no: {
				type: DataTypes.STRING,
				allowNull: false,
			},
			activity_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'activities',
					key: 'id',
				},
			},
			member_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'members',
					key: 'id',
				},
			},
			payment_status: {
				type: DataTypes.ENUM('Unpaid', 'Partially Paid', 'Paid'),
				allowNull: false,
				defaultValue: 'Unpaid',
			},
			payment_method: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			payment: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			date_time: {
				type: DataTypes.DATE,
				allowNull: false,
			},
			participants: {
				type: DataTypes.INTEGER,
				allowNull: false,
				defaultValue: 1,
			},
			price: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
			},
			price_type: {
				type: DataTypes.ENUM('per person', 'fixed'),
				allowNull: false,
				defaultValue: 'per person',
			},
			total: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
			},
			status: {
				type: DataTypes.ENUM('Unpaid', 'Completed', 'Pending'),
				allowNull: false,
				defaultValue: 'Unpaid',
			},
		},
		{
			tableName: 'activity_bookings',
			timestamps: true,
		},
	);

	ActivityBookings.associate = (models) => {
		ActivityBookings.belongsTo(models.Activities, {
			foreignKey: 'activity_id',
			as: 'activity',
		});

		ActivityBookings.belongsTo(models.Members, {
			foreignKey: 'member_id',
			as: 'member',
		});
	};

	return ActivityBookings;
};
