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

module.exports = (sequelize) => {
	const Routes = sequelize.define(
		'Routes',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			from: {
				type: DataTypes.STRING,
				allowNull: false,
			},
			to: {
				type: DataTypes.STRING,
				allowNull: false,
			},
			direction: {
				type: DataTypes.STRING,
				allowNull: false,
			},
		},
		{
			tableName: 'routes',
			timestamps: true,
		},
	);

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

	return Routes;
};
