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

module.exports = (sequelize) => {
	const AccessoryCheckout = sequelize.define(
		'AccessoryCheckout',
		{
			id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
			accessory_id: { type: DataTypes.INTEGER, allowNull: false },
			assigned_to: { type: DataTypes.INTEGER, allowNull: false },
			note: { type: DataTypes.TEXT, allowNull: true },
			creation: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
			modified: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
			assigned_by: { type: DataTypes.INTEGER, allowNull: true }
		},
		{
			tableName: 'accessorycheckouts',
			timestamps: false
		}
	);

	AccessoryCheckout.associate = (models) => {
		AccessoryCheckout.belongsTo(models.Accessory, { foreignKey: 'accessory_id', as: 'accessory' });
		AccessoryCheckout.belongsTo(models.Employee, { foreignKey: 'assigned_to', as: 'employee' });
	};

	return AccessoryCheckout;
};
