import {
  PrivateAlbumsResponse,
  PrivateAlbumsResponseSchema,
  PrivateAlbumUnlockResponse,
  PrivateAlbumUnlockResponseSchema,
  UnlockPrivateAlbumRequest,
} from "@/data/schemas/private-zone";

import { ApiPath } from "./api_path";
import { httpClient } from "./http_client";
import { type ApiEnvelope, unwrap } from "./response_helper";

export interface GetPrivateAlbumsInput {
  characterId: string;
  limit?: number;
}

export class PrivateZoneApi {
  async getAlbums(
    input: GetPrivateAlbumsInput,
  ): Promise<PrivateAlbumsResponse> {
    const env = await httpClient<ApiEnvelope<unknown>>(
      ApiPath.privateZoneAlbums,
      {
        query: {
          characterId: input.characterId,
          limit: input.limit ?? 20,
        },
      },
    );
    return PrivateAlbumsResponseSchema.parse(unwrap(env));
  }

  async unlockAlbum(
    albumId: string,
    body: UnlockPrivateAlbumRequest,
  ): Promise<PrivateAlbumUnlockResponse> {
    const env = await httpClient<ApiEnvelope<unknown>>(
      ApiPath.privateZoneAlbumUnlock(albumId),
      {
        method: "POST",
        body,
      },
    );
    return PrivateAlbumUnlockResponseSchema.parse(unwrap(env));
  }
}

export const privateZoneApi = new PrivateZoneApi();
