const { DataTypes } = require("sequelize");
const { report } = require("./companies.controller");

module.exports = (sequelize) => {
    const CompanyAsset = sequelize.define(
        "companyasset",
        {
            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 },

            logo: { type: DataTypes.STRING, allowNull: true },
            navbar_logo: { type: DataTypes.STRING, allowNull: true },
            login_logo: { type: DataTypes.STRING, allowNull: true },
            loading_logo: { type: DataTypes.STRING, allowNull: true },
            report_logo: { type: DataTypes.STRING, allowNull: true },
            favicon: { type: DataTypes.STRING, allowNull: true },

            company_id: {
                type: DataTypes.INTEGER,
                allowNull: false,
                references: {
                    model: 'companies',
                    key: 'id'
                }
            },
        },
        {
            tableName: 'companyassets',
        },
        {
            freezeTableName: true,
        }
    );

    /**
     * Define associations between Company Asset and other models.
     * @param {object} models - The models to associate with.
     */
    CompanyAsset.associate = (models) => {
        CompanyAsset.belongsTo(models.Company, {
            foreignKey: 'company_id',
            onDelete: 'CASCADE',
            as: 'company',
        });
    };

    return CompanyAsset;
};
