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

module.exports = (sequelize) => {
	const RestaurantHours = sequelize.define(
		'RestaurantHours',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			restaurant_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'restaurants',
					key: 'id',
				},
			},
			day_of_week: {
				type: DataTypes.INTEGER,
				allowNull: false,
			},
			open_time: {
				type: DataTypes.TIME,
				allowNull: true,
			},
			close_time: {
				type: DataTypes.TIME,
				allowNull: true,
			},
			is_closed: {
				type: DataTypes.BOOLEAN,
				allowNull: false,
				defaultValue: false,
			},
		},
		{
			tableName: 'restaurant_hours',
			timestamps: false,
		},
	);

	RestaurantHours.associate = (models) => {
		RestaurantHours.belongsTo(models.Restaurants, {
			foreignKey: 'restaurant_id',
			as: 'restaurant',
		});
	};

	return RestaurantHours;
};
