const { Model, DataTypes } = require('sequelize');
const sequelize = require('../config/db.js');

class EntityHeader extends Model {
    static associate(models) {
        EntityHeader.belongsTo(models.Entity, {
            as: 'entity',
            foreignKey: 'ent_id'
        });
    }
}

EntityHeader.init(
    {
        ent_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            unique: true,
            references: {
                model: 'entity',
                key: 'id'
            }
        },
        header_type: {
            type: DataTypes.ENUM('logo_only', 'logo_entity_name', 'logo_custom_text', 'entity_name_only', 'custom_text_only'),
            allowNull: false
        },
        custom_text: {
            type: DataTypes.STRING(150),
            allowNull: true
        },
        logo_filename: {
            type: DataTypes.STRING(255),
            allowNull: true
        },
        logo_path: {
            type: DataTypes.STRING(255),
            allowNull: true
        },
        mime_type: {
            type: DataTypes.STRING(100),
            allowNull: true
        },
        creatorId: {
            type: DataTypes.INTEGER,
            allowNull: false
        }
    },
    {
        sequelize,
        modelName: 'EntityHeader',
        tableName: 'entity_headers'
    }
);

module.exports = EntityHeader;
