'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
	async up(queryInterface, Sequelize) {
		await queryInterface.createTable('buses', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			bus_number: {
				type: Sequelize.STRING,
				allowNull: false,
				unique: true,
			},
			longitude: {
				type: Sequelize.DECIMAL(11, 8),
				allowNull: false,
			},
			latitude: {
				type: Sequelize.DECIMAL(10, 8),
				allowNull: false,
			},
		});

		await queryInterface.createTable('bus_stops', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			name: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			location: {
				type: Sequelize.TEXT,
				allowNull: false,
			},
			longitude: {
				type: Sequelize.DECIMAL(11, 8),
				allowNull: false,
			},
			latitude: {
				type: Sequelize.DECIMAL(10, 8),
				allowNull: false,
			},
		});

		await queryInterface.createTable('bus_schedules', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			from: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			to: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			direction: {
				type: Sequelize.STRING,
				allowNull: false,
			},
			date: {
				type: Sequelize.DATEONLY,
				allowNull: false,
			},
			times: {
				type: Sequelize.JSON,
				allowNull: false,
			},
		});
	},

	async down(queryInterface, Sequelize) {
		await queryInterface.dropTable('bus_schedules');
		await queryInterface.dropTable('bus_stops');
		await queryInterface.dropTable('buses');
	},
};
