"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WebsocketSDK=void 0;const errors_1=require("./errors"),requester_1=require("./requester");class WebsocketSDK{#t;constructor(t){this.#t=requester_1.Httpclient.createWebsocketHttpclient(t)}async send(t,e){let s="TEXT",r;typeof e=="string"?r=e:Buffer.isBuffer(e)?(r=e.toString("base64"),s="BINARY"):r=JSON.stringify(e);const a=Array.isArray(t)?t:[t];return a.length===1?await this.#a(a[0],{type:s,payload:r}):await this.#i(a,{type:s,payload:r})}async close(t,e){const s=Array.isArray(t)?t:[t];return s.length===1?await this.#n(s[0],e):await this.#c(s,e)}async isAlive(t){const e=Array.isArray(t)?t:[t];return e.length===1?await this.#o(e[0]):await this.#u(e)}async#a(t,e){const s=await this.#t.request({method:"POST",path:`/connection/send/${t}`,data:e});return this.#r(s)}async#i(t,e){const s=await this.#t.request({method:"POST",path:"/connection/batch/send",data:{connIds:t,message:e}});return this.#s(s)}async#n(t,e){const s=await this.#t.request({method:"POST",path:e?.status?`/connection/close/${e.status}/${t}`:`/connection/close/${t}`});return this.#r(s)}async#c(t,e){const s=await this.#t.request({method:"POST",path:"/connection/batch/close",data:{connIds:t,status:e?.status}});return this.#s(s)}async#o(t){const e=await this.#t.request({method:"GET",path:`/connection/isAlive/${t}`}),s=this.#e(e);return{isAlive:s.data,requestID:s.requestId||s.traceId}}async#u(t){const e=await this.#t.request({method:"POST",path:"/connection/batch/isAlive",data:{connIds:t}});return this.#s(e)}#e(t){if(t.status!==200){const{errorCode:e,resultMsg:s,detailMsg:r,traceId:a,requestId:i}=t.data||{},n=s??"\u7F51\u7EDC\u5F02\u5E38";throw errors_1.errors.WEBSOCKET_ERR(n,e?`${e}(${t.status})`:`${t.status}`,r,a||i)}if(!t.data.success){const{errorCode:e,resultMsg:s,detailMsg:r,traceId:a,requestId:i}=t.data;throw errors_1.errors.WEBSOCKET_ERR(s,e,r,a||i)}return t.data}#r(t){const e=this.#e(t);return{success:e.data,requestID:e.requestId||e.traceId}}#s(t){const e=this.#e(t);return{requestID:e.requestId||e.traceId,...e.data}}}exports.WebsocketSDK=WebsocketSDK;