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

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

	LicenseSeat.associate = (models) => {
		LicenseSeat.belongsTo(models.License, { foreignKey: 'license_id', as: 'license' });
		LicenseSeat.belongsTo(models.Employee, { foreignKey: 'assigned_to', as: 'employee' });
		LicenseSeat.belongsTo(models.Asset, { foreignKey: 'asset_id', as: 'asset' });
	};

	return LicenseSeat;
};
