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

module.exports = (sequelize) => {
	const RouteSchedules = sequelize.define(
		'RouteSchedules',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			route_id: {
				type: DataTypes.UUID,
				allowNull: false,
			},
			start_time: {
				type: DataTypes.TIME,
				allowNull: true,
			},
			end_time: {
				type: DataTypes.TIME,
				allowNull: true,
			},
		},
		{
			tableName: 'route_schedules',
			timestamps: true,
		},
	);

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

	return RouteSchedules;
};
