const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
	const BusSchedules = sequelize.define(
		'BusSchedules',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			route_id: {
				type: DataTypes.UUID,
				allowNull: false,
			},
			driver_id: {
				type: DataTypes.UUID,
				allowNull: true,
			},
			route_schedule_id: {
				type: DataTypes.UUID,
				allowNull: false,
			},
			date: {
				type: DataTypes.DATEONLY,
				allowNull: false,
			},
			start_time: {
				type: DataTypes.TIME,
				allowNull: true,
			},
			start_status: {
				type: DataTypes.ENUM('On Time', 'Late', 'Early'),
				allowNull: true,
			},
			finish_time: {
				type: DataTypes.TIME,
				allowNull: true,
			},
			finish_status: {
				type: DataTypes.ENUM('On Time', 'Late', 'Early'),
				allowNull: true,
			},
		},
		{
			tableName: 'bus_schedules',
			timestamps: true,
		},
	);

	BusSchedules.associate = (models) => {
		BusSchedules.belongsTo(models.Routes, { foreignKey: 'route_id', as: 'route' });
		BusSchedules.belongsTo(models.RouteSchedules, { foreignKey: 'route_schedule_id', as: 'schedule' });
	};

	return BusSchedules;
};
