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

module.exports = (sequelize) => {
    const Manufacturer = sequelize.define('manufacturer', {
        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
        name: { type: DataTypes.STRING(150), allowNull: false },
        display_name: { type: DataTypes.STRING(150), allowNull: false },
        address: { type: DataTypes.TEXT, allowNull: true },
        phone: { type: DataTypes.STRING(50), allowNull: true },
        mobile_no: { type: DataTypes.STRING(50), allowNull: true },
        email: { type: DataTypes.STRING(50), allowNull: true },
        website: { type: DataTypes.STRING(50), allowNull: true },
        logo: { type: DataTypes.STRING, allowNull: true },
        image: { type: DataTypes.STRING, allowNull: true },
        description: { type: DataTypes.TEXT, allowNull: true },

        // fk
    }, {
        tableName: 'manufacturers',
        freezeTableName: true
    });

    /**
     * Associates the Manufacturer model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    Manufacturer.associate = (models) => {
        Manufacturer.hasMany(models.Medicine, { foreignKey: 'manufacture_id', as: 'medicines' });
    };

    return Manufacturer;
};
