module.exports = (sequelize, DataTypes) => { const Plan = sequelize.define('Plan', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true }, conversation_id: { type: DataTypes.UUID, allowNull: false, references: { model: 'conversations', key: 'id' } }, title: { type: DataTypes.STRING, allowNull: false }, description: { type: DataTypes.TEXT, allowNull: false }, steps: { type: DataTypes.JSONB, allowNull: false }, status: { type: DataTypes.ENUM('draft', 'pending_approval', 'approved', 'rejected', 'executing', 'completed', 'failed'), defaultValue: 'draft' }, approval_feedback: { type: DataTypes.TEXT, allowNull: true }, execution_result: { type: DataTypes.JSONB, defaultValue: {} }, tools_required: { type: DataTypes.ARRAY(DataTypes.STRING), defaultValue: [] }, estimated_duration: { type: DataTypes.INTEGER, // in minutes allowNull: true }, complexity_score: { type: DataTypes.FLOAT, defaultValue: 0 }, metadata: { type: DataTypes.JSONB, defaultValue: {} } }, { tableName: 'plans', indexes: [ { fields: ['conversation_id'] }, { fields: ['status'] }, { fields: ['created_at'] } ] }); return Plan; };