module.exports = (sequelize, DataTypes) => { const ToolExecution = sequelize.define('ToolExecution', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true }, plan_id: { type: DataTypes.UUID, allowNull: false, references: { model: 'plans', key: 'id' } }, document_id: { type: DataTypes.UUID, allowNull: true, references: { model: 'documents', key: 'id' } }, tool_name: { type: DataTypes.STRING, allowNull: false }, tool_type: { type: DataTypes.ENUM('query_expander', 'extraction', 'report1', 'report2', 'web_search', 'encyclopedia_pdf'), allowNull: false }, input_parameters: { type: DataTypes.JSONB, allowNull: false }, output_result: { type: DataTypes.JSONB, allowNull: true }, status: { type: DataTypes.ENUM('pending', 'running', 'completed', 'failed'), defaultValue: 'pending' }, execution_time: { type: DataTypes.FLOAT, allowNull: true }, error_message: { type: DataTypes.TEXT, allowNull: true }, tokens_used: { type: DataTypes.INTEGER, defaultValue: 0 }, metadata: { type: DataTypes.JSONB, defaultValue: {} } }, { tableName: 'tool_executions', indexes: [ { fields: ['plan_id'] }, { fields: ['document_id'] }, { fields: ['tool_name'] }, { fields: ['tool_type'] }, { fields: ['status'] }, { fields: ['created_at'] } ] }); return ToolExecution; };