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

module.exports = (sequelize) => {
	const ConsumableCheckout = sequelize.define(
		'ConsumableCheckout',
		{
			id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
			consumable_id: { type: DataTypes.INTEGER, allowNull: false },
			assigned_to: { type: DataTypes.INTEGER, allowNull: true },
			asset_id: { type: DataTypes.INTEGER, allowNull: true },
			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: 'consumablecheckouts',
			timestamps: false
		}
	);

	ConsumableCheckout.associate = (models) => {
		ConsumableCheckout.belongsTo(models.Consumable, { foreignKey: 'consumable_id', as: 'consumable' });
		ConsumableCheckout.belongsTo(models.Employee, { foreignKey: 'assigned_to', as: 'employee' });
	};

	return ConsumableCheckout;
};
