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

module.exports = (sequelize) => {
	const AssetStatusLabel = sequelize.define(
		"assetstatuslabel",
		{
			id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true },
			creation: { type: DataTypes.DATE, allowNull: false },
			modified: { type: DataTypes.DATE, allowNull: false },
			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 },
			type: { type: DataTypes.STRING(50), allowNull: true },
			color: { type: DataTypes.STRING(20), allowNull: true },
			company_id: { type: DataTypes.INTEGER, allowNull: true },
		},
		{
			tableName: "assetstatuslabels",
			freezeTableName: true,
			indexes: [
				{ name: "idx_assetstatuslabels_company_id", fields: ["company_id"] },
				{ name: "idx_assetstatuslabels_enabled", fields: ["enabled"] },
			],
		}
	);

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

	return AssetStatusLabel;
};
