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

module.exports = (sequelize) => {
	const AssetManufacturer = sequelize.define(
		"assetmanufacturer",
		{
			id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true },
			creation: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
			modified: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
			modified_by: { type: DataTypes.INTEGER, allowNull: false },
			owner: { type: DataTypes.INTEGER, allowNull: false },
			createdAt: { type: DataTypes.DATE, allowNull: true, field: "createdAt" },
			updatedAt: { type: DataTypes.DATE, allowNull: true, field: "updatedAt" },
			enabled: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true },
			name: { type: DataTypes.STRING(150), allowNull: false },
			display_name: { type: DataTypes.STRING(150), allowNull: false },
			description: { type: DataTypes.TEXT, allowNull: true },
			company_id: { type: DataTypes.INTEGER, allowNull: true },
		},
		{
			tableName: "assetmanufacturers",
			freezeTableName: true,
			indexes: [
				{ name: "idx_assetmanufacturers_company_id", fields: ["company_id"] },
				{ name: "idx_assetmanufacturers_enabled", fields: ["enabled"] },
			],
		}
	);

	AssetManufacturer.associate = (models) => {
		AssetManufacturer.belongsTo(models.Company, { foreignKey: "company_id", as: "company" });
	};

	return AssetManufacturer;
};
