'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
	async up(queryInterface, Sequelize) {
		await queryInterface.createTable('concerns', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			type: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: true,
				references: {
					model: 'members',
					key: 'id',
				},
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
			is_resolved: {
				type: Sequelize.BOOLEAN,
				defaultValue: false,
			},
		});

		await queryInterface.createTable('concern_messages', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			concernId: {
				type: Sequelize.UUID,
				allowNull: false,
				references: {
					model: 'concerns',
					key: 'id',
				},
				onDelete: 'CASCADE',
			},
			message: {
				type: Sequelize.TEXT,
				allowNull: false,
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: true,
			},
			from_member: {
				type: Sequelize.BOOLEAN,
				allowNull: false,
				defaultValue: true,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
		});
	},

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