var E=Object.defineProperty;var r=(t,e)=>E(t,"name",{value:e,configurable:!0});var L=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})};import{createDiagnosticCollector as M,navigateType as K}from"@typespec/compiler";import"@typespec/compiler";import{useStateMap as k,useStateSet as g}from"@typespec/compiler/utils";import{createTypeSpecLibrary as C,paramMessage as D}from"@typespec/compiler";var $=C({name:"@typespec/events",diagnostics:{"invalid-content-type-target":{severity:"error",messages:{default:"@contentType can only be specified on the top-level event envelope, or the event payload marked with @data"}},"multiple-event-payloads":{severity:"error",messages:{default:D`Event payload already applied to ${"dataPath"} but also exists under ${"currentPath"}`,payloadInIndexedModel:D`Event payload applied from inside a Record or Array at ${"dataPath"}`}}},state:{events:{description:"State for the @events decorator."},contentType:{description:"State for the @contentType decorator."},data:{description:"State for the @data decorator."}}}),{reportDiagnostic:q,createDiagnostic:i,stateKeys:v}=$;var[N,w]=g(v.events),O=r((t,e)=>{w(t.program,e)},"$eventsDecorator");var[m,I]=k(v.contentType),Q=r((t,e,n)=>{I(t.program,e,n)},"$contentTypeDecorator");var[P,b]=g(v.data),U=r((t,e)=>{b(t.program,e)},"$dataDecorator");function j(t,e){if(!(!m(t,e)||P(t,e)))return i({code:"invalid-content-type-target",target:e})}r(j,"validateContentType");function d(t){return t.map(e=>{switch(e.kind){case"ModelProperty":return e.name;case"Tuple":return"[]";case"Model":return}}).filter(Boolean).join(".")}r(d,"stringifyPropertyPath");function A(t,e){let n=M(),c=typeof e.name=="string"?e.name:void 0,l=m(t,e),s,x,y="",h=0,a=[],f=new Set;K(e.type,{modelProperty(o){a.push(o);let u=j(t,o);if(u&&n.add(u),f.has(o.type)){n.add(i({code:"multiple-event-payloads",format:{dataPath:y,currentPath:d(a)},target:e}));return}if(P(t,o)){if(a.forEach(p=>{p.kind==="ModelProperty"?f.add(p.type):(p.kind==="Model"||p.kind==="Tuple")&&f.add(p)}),h>0){n.add(i({code:"multiple-event-payloads",messageId:"payloadInIndexedModel",format:{dataPath:d(a.slice(0,-1))},target:e}));return}if(s){n.add(i({code:"multiple-event-payloads",format:{dataPath:y,currentPath:d(a)},target:e}));return}s=o.type,x=m(t,o),y=d(a)}},exitModelProperty(){a.pop()},tuple(o){a.push(o),o.values.forEach(u=>{if(f.has(u)){n.add(i({code:"multiple-event-payloads",format:{dataPath:y,currentPath:d(a)},target:e}));return}})},exitTuple(){a.pop()},model(o){o.indexer&&h++,a.push(o)},exitModel(o){o.indexer&&h--,a.pop()}},{});let S={eventType:c,root:e,isEventEnvelope:!!s,type:e.type,contentType:l,payloadType:s??e.type,payloadContentType:s?x:l};return n.wrap(S)}r(A,"getEventDefinition");function B(t,e){let n=M(),c=[];return e.variants.forEach(l=>{c.push(n.pipe(A(t,l)))}),n.wrap(c)}r(B,"getEventDefinitions");export{r as a,L as b,$ as c,v as d,N as e,O as f,m as g,Q as h,P as i,U as j,B as k};
