const { UUID, UUIDV4, DATE, ENUM, DECIMAL, STRING } = require('sequelize');

module.exports = (sequelize, DataTypes) => {
	const EventRegistrations = sequelize.define(
		'EventRegistrations',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			reference_no: {
				type: DataTypes.STRING,
				allowNull: false,
				unique: true,
			},
			member_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'members',
					key: 'id',
				},
			},
			event_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'events',
					key: 'id',
				},
			},
			payment_status: {
				type: DataTypes.ENUM('Unpaid', 'Partially Paid', 'Paid'),
				allowNull: false,
				defaultValue: 'Unpaid',
			},
			status: {
				type: DataTypes.ENUM('Unpaid', 'Successful', 'Failed'),
				allowNull: false,
				defaultValue: 'Successfull',
			},
			payment: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			payment_method: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			price: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			service_fee: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			taxes: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			total: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			createdAt: {
				type: DataTypes.DATE,
				allowNull: false,
				defaultValue: DataTypes.NOW,
			},
			updatedAt: {
				type: DataTypes.DATE,
				allowNull: false,
				defaultValue: DataTypes.NOW,
			},
		},
		{
			tableName: 'event_registrations',
			timestamps: false,
		},
	);

	EventRegistrations.associate = (models) => {
		EventRegistrations.belongsTo(models.Members, { as: 'member', foreignKey: 'member_id' });
		EventRegistrations.belongsTo(models.Events, { as: 'event', foreignKey: 'event_id' });
	};

	return EventRegistrations;
};
