'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
	async up(queryInterface, Sequelize) {
		await queryInterface.dropTable('drivers');

		await queryInterface.createTable('drivers', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			driver_name: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			conductor_name: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			email_address: {
				type: Sequelize.STRING,
				allowNull: false,
				unique: true,
			},
			password: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			shuttle_number: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			plate_number: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			driver_photo: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			vehicle_photo: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			status: {
				type: Sequelize.ENUM('online', 'offline'),
				allowNull: false,
				defaultValue: 'offline',
			},
			createdAt: {
				allowNull: false,
				type: Sequelize.DATE,
				defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
			},
			updatedAt: {
				allowNull: false,
				type: Sequelize.DATE,
				defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
			},
		});
	},

	async down(queryInterface, Sequelize) {
		await queryInterface.createTable('drivers', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			first_name: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			middle_name: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			last_name: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			phone_no: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			email_address: {
				type: Sequelize.STRING,
				allowNull: false,
				unique: true,
			},
			password: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			conductor_name: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			shuttle_number: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			plate_number: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			driver_photo: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			vehicle_photo: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			status: {
				type: Sequelize.ENUM('active', 'inactive'),
				allowNull: false,
				defaultValue: 'active',
			},
			createdAt: {
				allowNull: false,
				type: Sequelize.DATE,
			},
			updatedAt: {
				allowNull: false,
				type: Sequelize.DATE,
			},
		});

		await queryInterface.dropTable('drivers');
	},
};
