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

export interface WorkflowStageConfigAttributes {
    id: string;
    stageName: string;
    stageOrder: number;
    colorCode: string | null;
    isParallel: boolean;
    defaultEvaluators: any[];
    isActive: boolean;
}

export interface WorkflowStageConfigInstance extends Model<WorkflowStageConfigAttributes>, WorkflowStageConfigAttributes { }

export default (sequelize: Sequelize) => {
    const WorkflowStageConfig = sequelize.define<WorkflowStageConfigInstance>('WorkflowStageConfig', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        stageName: {
            type: DataTypes.STRING,
            unique: true,
            allowNull: false
        },
        stageOrder: {
            type: DataTypes.INTEGER,
            allowNull: false
        },
        colorCode: {
            type: DataTypes.STRING,
            allowNull: true
        },
        isParallel: {
            type: DataTypes.BOOLEAN,
            defaultValue: false
        },
        defaultEvaluators: {
            type: DataTypes.JSON,
            defaultValue: []
        },
        isActive: {
            type: DataTypes.BOOLEAN,
            defaultValue: true
        }
    }, {
        tableName: 'workflow_stages_config',
        timestamps: true,
        indexes: [
            { fields: ['stageName'] },
            { fields: ['stageOrder'] }
        ]
    });

    (WorkflowStageConfig as any).associate = (models: any) => {
        // Future associations with applications or tasks
    };

    return WorkflowStageConfig;
};
