import {
  createBlockchainWalletsResource,
  init_blockchain
} from "./chunk-FG25JHDX.mjs";
import {
  createCustodialWalletsResource,
  init_custodial
} from "./chunk-KMU6V4LW.mjs";
import {
  createOfframpWalletsResource,
  init_offramp
} from "./chunk-QGNLMN6Z.mjs";
import {
  createTransfersResource,
  init_transfers
} from "./chunk-ISHZTBAN.mjs";
import {
  createUploadResource,
  init_upload
} from "./chunk-UDRMLZWT.mjs";
import {
  createVirtualAccountsResource,
  init_virtual_accounts
} from "./chunk-LEPGLH7Q.mjs";
import {
  createWebhookEndpointsResource,
  init_webhooks
} from "./chunk-UC57SCKQ.mjs";
import {
  createPayinQuotesResource,
  init_quotes
} from "./chunk-E7M4CJKR.mjs";
import {
  createPayoutsResource,
  init_payouts
} from "./chunk-F5Z45GCA.mjs";
import {
  createQuotesResource,
  init_quotes as init_quotes2
} from "./chunk-TBTA7A2P.mjs";
import {
  createReceiversResource,
  init_receivers
} from "./chunk-YIZJM2GU.mjs";
import {
  createTermsOfServiceResource,
  init_terms_of_service
} from "./chunk-Z6EYX4D3.mjs";
import {
  createFeesResource,
  init_fees
} from "./chunk-ALHMJWQN.mjs";
import {
  createInstancesResource,
  init_instances
} from "./chunk-B5T7AQLH.mjs";
import {
  createPartnerFeesResource,
  init_partner_fees
} from "./chunk-RC5NN5UF.mjs";
import {
  createPayinsResource,
  init_payins
} from "./chunk-VGU72ZNI.mjs";
import {
  createApiKeysResource,
  init_api_keys
} from "./chunk-LRHWT4JU.mjs";
import {
  createAvailableResource,
  init_available
} from "./chunk-WE73MTQL.mjs";
import {
  createBankAccountsResource,
  init_bank_accounts
} from "./chunk-UOAM7SX3.mjs";
import {
  __async,
  __esm,
  __spreadProps,
  __spreadValues
} from "./chunk-OBKEW4AQ.mjs";

// package.json
var version;
var init_package = __esm({
  "package.json"() {
    version = "3.4.1";
  }
});

// src/internal/blindpay-error.ts
var BlindPayError;
var init_blindpay_error = __esm({
  "src/internal/blindpay-error.ts"() {
    "use strict";
    BlindPayError = class extends Error {
      constructor(message) {
        super(message);
        this.name = "BlindpayError";
      }
    };
  }
});

// src/client.ts
import { Webhook } from "svix";
var BlindPay;
var init_client = __esm({
  "src/client.ts"() {
    "use strict";
    init_package();
    init_blindpay_error();
    init_api_keys();
    init_available();
    init_bank_accounts();
    init_fees();
    init_instances();
    init_partner_fees();
    init_payins();
    init_quotes();
    init_payouts();
    init_quotes2();
    init_receivers();
    init_terms_of_service();
    init_transfers();
    init_upload();
    init_virtual_accounts();
    init_blockchain();
    init_custodial();
    init_offramp();
    init_webhooks();
    BlindPay = class {
      constructor({
        apiKey,
        instanceId
      }) {
        // Options
        this.baseUrl = "https://api.blindpay.com/v1";
        if (!apiKey) {
          throw new BlindPayError("Api key not provided, get your api key on blindpay dashboard");
        }
        if (!instanceId) {
          throw new BlindPayError(
            "Instance id not provided, get your instance id on blindpay dashboard"
          );
        }
        this.apiKey = apiKey;
        this.instanceId = instanceId;
        this.headers = {
          "Content-Type": "application/json",
          Accept: "application/json",
          "User-Agent": `blindpay-node/${version}`,
          Authorization: `Bearer ${this.apiKey}`
        };
        this.api = {
          get: this.get.bind(this),
          post: this.post.bind(this),
          put: this.put.bind(this),
          patch: this.patch.bind(this),
          delete: this.delete.bind(this)
        };
        this.available = createAvailableResource(this.api);
        this.instances = __spreadProps(__spreadValues({}, createInstancesResource(this.instanceId, this.api)), {
          apiKeys: createApiKeysResource(this.instanceId, this.api),
          webhookEndpoints: createWebhookEndpointsResource(this.instanceId, this.api),
          tos: createTermsOfServiceResource(this.instanceId, this.api)
        });
        this.partnerFees = createPartnerFeesResource(this.instanceId, this.api);
        this.payins = __spreadProps(__spreadValues({}, createPayinsResource(this.instanceId, this.api)), {
          quotes: createPayinQuotesResource(this.instanceId, this.api)
        });
        this.quotes = createQuotesResource(this.instanceId, this.api);
        this.payouts = createPayoutsResource(this.instanceId, this.api);
        this.transfers = createTransfersResource(this.instanceId, this.api);
        this.fees = createFeesResource(this.instanceId, this.api);
        this.upload = createUploadResource(this.baseUrl, this.headers);
        this.receivers = __spreadProps(__spreadValues({}, createReceiversResource(this.instanceId, this.api)), {
          bankAccounts: createBankAccountsResource(this.instanceId, this.api)
        });
        this.virtualAccounts = createVirtualAccountsResource(this.instanceId, this.api);
        this.wallets = {
          blockchain: createBlockchainWalletsResource(this.instanceId, this.api),
          offramp: createOfframpWalletsResource(this.instanceId, this.api),
          custodial: createCustodialWalletsResource(this.instanceId, this.api)
        };
      }
      request(method, path, body) {
        return __async(this, null, function* () {
          var _a;
          try {
            const response = yield fetch(`${this.baseUrl}${path}`, {
              method,
              headers: this.headers,
              body: body ? JSON.stringify(body) : void 0
            });
            if (!response.ok) {
              const error = yield response.json();
              return {
                data: null,
                error: {
                  message: (_a = error == null ? void 0 : error.message) != null ? _a : "Unknown error"
                }
              };
            }
            const data = yield response.json();
            return {
              data,
              error: null
            };
          } catch (error) {
            if (error instanceof Error) {
              return {
                data: null,
                error: {
                  message: error.message
                }
              };
            }
            const errorMessage = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "Unknown error";
            return {
              data: null,
              error: {
                message: errorMessage
              }
            };
          }
        });
      }
      get(path) {
        return __async(this, null, function* () {
          return this.request("GET", path);
        });
      }
      post(path, body) {
        return __async(this, null, function* () {
          return this.request("POST", path, body);
        });
      }
      put(path, body) {
        return __async(this, null, function* () {
          return this.request("PUT", path, body);
        });
      }
      patch(path, body) {
        return __async(this, null, function* () {
          return this.request("PATCH", path, body);
        });
      }
      delete(path, body) {
        return __async(this, null, function* () {
          return this.request("DELETE", path, body);
        });
      }
      /**
       * Verifies the BlindPay webhook signature using Svix
       *
       * @param params.secret The webhook secret from BlindPay dashboard
       * @param params.headers The webhook headers object containing svix-id, svix-timestamp, and svix-signature
       * @param params.payload The raw request body as a string
       * @returns {boolean} True if the signature is valid, false otherwise
       */
      verifyWebhookSignature({
        secret,
        headers,
        payload
      }) {
        try {
          const webhook = new Webhook(secret);
          webhook.verify(payload, {
            "svix-id": headers.id,
            "svix-timestamp": headers.timestamp,
            "svix-signature": headers.signature
          });
          return true;
        } catch (e) {
          return false;
        }
      }
    };
  }
});

export {
  BlindPay,
  init_client
};
