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

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

            // main
            enabled: { type: DataTypes.BOOLEAN, allowNull: false },
            currency_name: { type: DataTypes.STRING(50), allowNull: false },
            symbol: { type: DataTypes.STRING(50), allowNull: true },
            symbol_on_right: { type: DataTypes.BOOLEAN, allowNull: true },

            // fk
            company_id: { type: DataTypes.INTEGER, allowNull: true },
        },
        {
            tableName: "currencies",
            freezeTableName: true,
        }
    );

    /**
     * Associates the EmployeeGroup model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    Currency.associate = (models) => {
        Currency.belongsTo(models.Company, { as: "company", foreignKey: "company_id" });
    };

    return Currency;
};
