// @bun
var{defineProperty:c,getOwnPropertyNames:d,getOwnPropertyDescriptor:x}=Object,l=Object.prototype.hasOwnProperty;function f(e){return this[e]}var m=(e)=>{var t=(g??=new WeakMap).get(e),i;if(t)return t;if(t=c({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var s of d(e))if(!l.call(t,s))c(t,s,{get:f.bind(e,s),enumerable:!(i=x(e,s))||i.enumerable})}return g.set(e,t),t},g;var E=(e)=>e;function A(e,t){this[e]=E.bind(null,t)}var _=(e,t)=>{for(var i in t)c(e,i,{get:t[i],enumerable:!0,configurable:!0,set:A.bind(t,i)})};var k=(e,t)=>()=>(e&&(t=e(e=0)),t);class P{deps;constructor(e={}){this.deps=e}async execute(e,t,i={}){let s=new Date,a=[];for(let[r,n]of t.actions.entries()){let o=await this.executeAction({index:r,action:n,context:e,proposal:t,options:i});a.push(o)}let p=new Date,u=R(a);return{proposalId:t.id,contextId:e.id,startedAt:s,finishedAt:p,status:u,actions:a}}async executeAction({index:e,action:t,context:i,proposal:s,options:a}){let p=new Date,u=a.dryRun??!1,r=(n,o={})=>({index:e,action:t,status:n,startedAt:p,finishedAt:new Date,reason:o.reason,output:o.output,error:o.error});if(u)return r("skipped",{reason:"dry_run"});try{switch(t.kind){case"update_blueprint":{let n=this.deps.blueprintUpdater;if(!n)return r("skipped",{reason:"missing_blueprint_updater"});let o=await n.applyBlueprintUpdate(i,s,t);return r("success",{output:o})}case"update_tenant_config":{let n=this.deps.tenantConfigUpdater;if(!n)return r("skipped",{reason:"missing_tenant_config_updater"});let o=await n.applyTenantConfigUpdate(i,s,t);return r("success",{output:o})}case"run_tests":{let n=this.deps.testExecutor;if(!n)return r("skipped",{reason:"missing_test_executor"});let o=await n.runTests(i,s,t);return r("success",{output:o})}case"run_migrations":{let n=this.deps.migrationExecutor;if(!n)return r("skipped",{reason:"missing_migration_executor"});let o=await n.runMigrations(i,s,t);return r("success",{output:o})}case"trigger_regeneration":{let n=this.deps.regenerationTrigger;if(!n)return r("skipped",{reason:"missing_regeneration_trigger"});let o=await n.triggerRegeneration(i,s,t);return r("success",{output:o})}default:return r("skipped",{reason:"unknown_action"})}}catch(n){return r("failed",{error:n instanceof Error?n:Error(String(n))})}}}function R(e){if(e.some((t)=>t.status==="failed"))return"failed";if(e.some((t)=>t.status==="success")&&e.some((t)=>t.status==="skipped"))return"partial";if(e.every((t)=>t.status==="skipped"))return"partial";return"success"}export{P as ProposalExecutor};
