var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tags_exports = {};
__export(tags_exports, {
  buildTagsApiClientMethods: () => buildTagsApiClientMethods
});
module.exports = __toCommonJS(tags_exports);
function buildTagsApiClientMethods(input) {
  const { request, handleApiError, normalizePositiveIntegerInput } = input;
  return {
    async fetchTagDirectory(options = {}) {
      const params = new URLSearchParams();
      if (typeof options.limit === "number") {
        params.set("limit", String(normalizePositiveIntegerInput(options.limit, "invalid_tags_limit")));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(normalizePositiveIntegerInput(options.offset, "invalid_tags_offset")));
      }
      if (typeof options.tagLimit === "number") {
        params.set("tagLimit", String(normalizePositiveIntegerInput(options.tagLimit, "invalid_tags_limit")));
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/tags/directory${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_tag_directory");
      }
      return response.body;
    },
    async fetchTags(options = {}) {
      const params = new URLSearchParams();
      if (typeof options.targetKind === "string" && options.targetKind.trim().length > 0) {
        params.set("targetKind", options.targetKind.trim());
      }
      if (typeof options.groupSlug === "string" && options.groupSlug.trim().length > 0) {
        params.set("groupSlug", options.groupSlug.trim());
      }
      if (typeof options.limit === "number") {
        params.set("limit", String(normalizePositiveIntegerInput(options.limit, "invalid_tags_limit")));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(normalizePositiveIntegerInput(options.offset, "invalid_tags_offset")));
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/tags${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_tags");
      }
      return response.body;
    },
    async fetchTag(groupSlug, tagSlug) {
      const normalizedGroupSlug = typeof groupSlug === "string" ? groupSlug.trim() : "";
      const normalizedTagSlug = typeof tagSlug === "string" ? tagSlug.trim() : "";
      if (!normalizedGroupSlug || !normalizedTagSlug) {
        throw new Error("invalid_tag_ref");
      }
      const response = await request({
        method: "GET",
        path: `/tags/${encodeURIComponent(normalizedGroupSlug)}/${encodeURIComponent(normalizedTagSlug)}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_tag");
      }
      return response.body;
    },
    async fetchTagGroup(groupSlug, options = {}) {
      const normalizedGroupSlug = typeof groupSlug === "string" ? groupSlug.trim() : "";
      if (!normalizedGroupSlug) {
        throw new Error("invalid_tag_group_slug");
      }
      const params = new URLSearchParams();
      if (typeof options.targetKind === "string" && options.targetKind.trim().length > 0) {
        params.set("targetKind", options.targetKind.trim());
      }
      if (typeof options.appType === "string" && options.appType.trim().length > 0) {
        params.set("appType", options.appType.trim());
      }
      if (typeof options.sort === "string" && options.sort.trim().length > 0) {
        params.set("sort", options.sort.trim());
      }
      if (typeof options.limit === "number") {
        params.set("limit", String(normalizePositiveIntegerInput(options.limit, "invalid_tags_limit")));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(normalizePositiveIntegerInput(options.offset, "invalid_tags_offset")));
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/tags/${encodeURIComponent(normalizedGroupSlug)}${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_tag_group");
      }
      return response.body;
    },
    async fetchAdminTagGroups() {
      const response = await request({
        method: "GET",
        path: "/admin/tag-groups"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_tag_groups");
      }
      return response.body;
    },
    async createAdminTagGroup(requestBody) {
      const response = await request({
        method: "POST",
        path: "/admin/tag-groups",
        body: requestBody
      });
      if (response.status !== 201) {
        handleApiError(response, "create_admin_tag_group");
      }
      return response.body;
    },
    async updateAdminTagGroup(groupSlug, requestBody) {
      const normalizedGroupSlug = typeof groupSlug === "string" ? groupSlug.trim() : "";
      if (!normalizedGroupSlug) {
        throw new Error("invalid_tag_group_slug");
      }
      const response = await request({
        method: "PATCH",
        path: `/admin/tag-groups/${encodeURIComponent(normalizedGroupSlug)}`,
        body: requestBody
      });
      if (response.status !== 200) {
        handleApiError(response, "update_admin_tag_group");
      }
      return response.body;
    },
    async createAdminTag(groupSlug, requestBody) {
      const normalizedGroupSlug = typeof groupSlug === "string" ? groupSlug.trim() : "";
      if (!normalizedGroupSlug) {
        throw new Error("invalid_tag_group_slug");
      }
      const response = await request({
        method: "POST",
        path: `/admin/tag-groups/${encodeURIComponent(normalizedGroupSlug)}/tags`,
        body: requestBody
      });
      if (response.status !== 201) {
        handleApiError(response, "create_admin_tag");
      }
      return response.body;
    },
    async updateAdminTag(groupSlug, tagSlug, requestBody) {
      const normalizedGroupSlug = typeof groupSlug === "string" ? groupSlug.trim() : "";
      const normalizedTagSlug = typeof tagSlug === "string" ? tagSlug.trim() : "";
      if (!normalizedGroupSlug || !normalizedTagSlug) {
        throw new Error("invalid_tag_ref");
      }
      const response = await request({
        method: "PATCH",
        path: `/admin/tags/${encodeURIComponent(normalizedGroupSlug)}/${encodeURIComponent(normalizedTagSlug)}`,
        body: requestBody
      });
      if (response.status !== 200) {
        handleApiError(response, "update_admin_tag");
      }
      return response.body;
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildTagsApiClientMethods
});
