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 game_ideas_exports = {};
__export(game_ideas_exports, {
  buildGameIdeasApiClientMethods: () => buildGameIdeasApiClientMethods
});
module.exports = __toCommonJS(game_ideas_exports);
var import_request = require("../core/request.js");
async function buildAuthorizedHeaders(input) {
  const headers = new Headers();
  for (const [key, value] of Object.entries(input.getClientHeaders())) {
    headers.set(key, value);
  }
  const token = await input.resolveToken();
  if (token) {
    headers.set("authorization", `Bearer ${token}`);
  }
  return headers;
}
function appendPaginationParams(params, options) {
  if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
    params.set("limit", String(options.limit));
  }
  if (typeof options.offset === "number" && Number.isFinite(options.offset)) {
    params.set("offset", String(options.offset));
  }
}
function normalizeIdOrSlug(value) {
  const normalized = typeof value === "string" ? value.trim() : "";
  if (!normalized) {
    throw new Error("invalid_game_idea_ref");
  }
  return normalized;
}
function buildGameIdeasApiClientMethods(input) {
  const { request, handleApiError, fetchImpl, includeBrowserCredentials, resolveBaseUrl, resolveUrl, parseResponseBody, resolveToken, getClientHeaders } = input;
  return {
    async createGameIdea(options) {
      const form = new FormData();
      form.set("payload", JSON.stringify(options.payload));
      if (options.image) {
        form.set("image", options.image, options.filename ?? "game-idea-image.png");
      }
      const headers = await buildAuthorizedHeaders({ getClientHeaders, resolveToken });
      const response = await fetchImpl(resolveUrl(resolveBaseUrl(), "/me/game-ideas"), {
        method: "POST",
        headers,
        body: form,
        ...(0, import_request.buildBrowserCredentialsInit)(includeBrowserCredentials)
      });
      const body = await parseResponseBody(response);
      const apiResponse = {
        status: response.status,
        body,
        headers: response.headers
      };
      if (response.status !== 201) {
        handleApiError(apiResponse, "create_game_idea");
      }
      return body;
    },
    async listGameIdeas(options = {}) {
      const params = new URLSearchParams();
      if (typeof options.state === "string" && options.state.trim().length > 0) {
        params.set("state", options.state.trim().toLowerCase());
      }
      appendPaginationParams(params, options);
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: "/me/game-ideas" + (query ? `?${query}` : "")
      });
      if (response.status !== 200) {
        handleApiError(response, "list_game_ideas");
      }
      return response.body;
    },
    async getGameIdea(idOrSlug) {
      const ref = normalizeIdOrSlug(idOrSlug);
      const response = await request({
        method: "GET",
        path: `/me/game-ideas/${encodeURIComponent(ref)}`
      });
      if (response.status !== 200) {
        handleApiError(response, "get_game_idea");
      }
      return response.body;
    },
    async getGameIdeaStatus(idOrSlug) {
      const ref = normalizeIdOrSlug(idOrSlug);
      const response = await request({
        method: "GET",
        path: `/me/game-ideas/${encodeURIComponent(ref)}/status`
      });
      if (response.status !== 200) {
        handleApiError(response, "get_game_idea_status");
      }
      return response.body;
    },
    async updateGameIdea(idOrSlug, body) {
      const ref = normalizeIdOrSlug(idOrSlug);
      const response = await request({
        method: "PATCH",
        path: `/me/game-ideas/${encodeURIComponent(ref)}`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "update_game_idea");
      }
      return response.body;
    },
    async startGameIdea(idOrSlug, body = {}) {
      const ref = normalizeIdOrSlug(idOrSlug);
      const appRef = typeof body.app === "string" ? body.app.trim() : "";
      const response = await request({
        method: "POST",
        path: `/me/game-ideas/${encodeURIComponent(ref)}/start`,
        ...appRef ? { body: { app: appRef } } : {}
      });
      if (response.status !== 200) {
        handleApiError(response, "start_game_idea");
      }
      return response.body;
    },
    async shipGameIdea(idOrSlug, body) {
      const ref = normalizeIdOrSlug(idOrSlug);
      const appRef = typeof body?.app === "string" ? body.app.trim() : "";
      if (!appRef) {
        throw new Error("invalid_app_ref");
      }
      const response = await request({
        method: "POST",
        path: `/me/game-ideas/${encodeURIComponent(ref)}/ship`,
        body: { app: appRef }
      });
      if (response.status !== 200) {
        handleApiError(response, "ship_game_idea");
      }
      return response.body;
    },
    async fetchRemixCandidates(options = {}) {
      const params = new URLSearchParams();
      if (typeof options.q === "string" && options.q.trim().length > 0) {
        params.set("q", options.q.trim());
      }
      appendPaginationParams(params, options);
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: "/game-ideas/remix-candidates" + (query ? `?${query}` : "")
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_remix_candidates");
      }
      return response.body;
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildGameIdeasApiClientMethods
});
