'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
	async up(queryInterface, Sequelize) {
		const { UUID, UUIDV4, STRING, ENUM, BOOLEAN, TEXT } = Sequelize;

		await queryInterface.createTable('members', {
			id: {
				type: UUID,
				defaultValue: UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			organization_name: {
				type: STRING,
				allowNull: true,
			},
			is_jci_senator: {
				type: ENUM('Yes', 'No'),
				allowNull: false,
			},
			local_org_name: {
				type: STRING,
				allowNull: true,
			},
			first_name: {
				type: STRING,
				allowNull: false,
			},
			last_name: {
				type: STRING,
				allowNull: false,
			},
			email_address: {
				type: STRING,
				allowNull: false,
				unique: true,
				validate: {
					isEmail: true,
				},
			},
			phone_number: {
				type: STRING(15),
				allowNull: true,
			},
			password: {
				type: STRING,
				allowNull: false,
			},
			is_tnc_agreed: {
				type: BOOLEAN,
				allowNull: false,
				defaultValue: false,
			},
			status: {
				type: BOOLEAN,
				allowNull: false,
				defaultValue: false,
			},
			profile_image: {
				type: TEXT,
				allowNull: true,
			},
			location: {
				type: TEXT,
				allowNull: true,
			},
			position: {
				type: STRING(100),
				allowNull: true,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
				defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
			},
			updatedAt: {
				type: Sequelize.DATE,
				allowNull: false,
				defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
			},
		});
	},

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