'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
	async up(queryInterface, Sequelize) {
		await queryInterface.createTable('event_registrations', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			reference_no: {
				type: Sequelize.STRING,
				allowNull: false,
				unique: true,
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'members',
					key: 'id',
				},
			},
			event_id: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'events',
					key: 'id',
				},
			},
			status: {
				type: Sequelize.ENUM('Successful', 'Failed'),
				allowNull: false,
				defaultValue: 'Successful',
			},
			payment: {
				type: Sequelize.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			payment_method: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			price: {
				type: Sequelize.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			service_fee: {
				type: Sequelize.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			taxes: {
				type: Sequelize.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			total: {
				type: Sequelize.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
				defaultValue: Sequelize.NOW,
			},
			updatedAt: {
				type: Sequelize.DATE,
				allowNull: false,
				defaultValue: Sequelize.NOW,
			},
		});

		await queryInterface.addIndex('event_registrations', ['member_id', 'event_id'], {
			unique: true,
			name: 'unique_member_event_registration',
		});
	},

	async down(queryInterface, Sequelize) {
		await queryInterface.dropTable('event_registrations');
	},
};
