import { Model, DataTypes, Sequelize } from 'sequelize';

export interface SystemConfigurationAttributes {
    id: string;
    key: string;
    value: any;
    category: string;
    description?: string;
    isActive: boolean;
}

export interface SystemConfigurationInstance extends Model<SystemConfigurationAttributes>, SystemConfigurationAttributes { }

export default (sequelize: Sequelize) => {
    const SystemConfiguration = sequelize.define<SystemConfigurationInstance>('SystemConfiguration', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        key: {
            type: DataTypes.STRING,
            allowNull: false,
            unique: true
        },
        value: {
            type: DataTypes.JSONB,
            allowNull: false
        },
        category: {
            type: DataTypes.STRING,
            allowNull: false
        },
        description: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        isActive: {
            type: DataTypes.BOOLEAN,
            defaultValue: true
        }
    }, {
        tableName: 'system_configurations',
        timestamps: true,
        indexes: [
            { fields: ['key'] },
            { fields: ['category'] }
        ]
    });

    return SystemConfiguration;
};
