"use strict";var __importDefault=this&&this.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FormDataBody=exports.AlipayFormData=void 0;const node_stream_1=require("node:stream"),formstream_1=__importDefault(require("formstream")),utils_1=require("../utils");class AlipayFormData{#e;#t;constructor(){this.#e=[],this.#t=[]}getFields(){return this.#t}getFiles(){return this.#e}addField(e,t){return this.#t.push({name:e,value:t}),this}addFile(e,t,s){const r={fieldName:e,name:t};return typeof s=="string"?r.path=s:Buffer.isBuffer(s)?r.content=s:r.stream=s,this.#e.push(r),this}}exports.AlipayFormData=AlipayFormData;class FormDataBody{#e;#t={};constructor(e){this.#e=new formstream_1.default({minChunkSize:1024*1024*2,...e})}signedBody(){return Object.keys(this.#t).sort().map(t=>`${t}=${this.#t[t]}`).join("&")}addField(e,t){const s=(0,utils_1.decamelize)(e),r=t&&typeof t=="object"?JSON.stringify(t):t;return this.#t[s]=r,this.#e.field(s,r),this}addFile(e){const t=(0,utils_1.decamelize)(e.fieldName);e.path?this.#e.file(t,e.path,e.name):e.stream?this.#e.stream(t,e.stream,e.name):e.content&&this.#e.buffer(t,e.content,e.name)}toReadable(){return new node_stream_1.Readable().wrap(this.#e)}headers(){return this.#e.headers()}static createFromAlipayFormData(e){const t=new FormDataBody;for(const s of e.getFields())t.addField(s.name,s.value);for(const s of e.getFiles())t.addFile(s);return t}}exports.FormDataBody=FormDataBody;