import {
  PrivateAlbumsResponse,
  PrivateAlbumUnlockResponse,
  UnlockPrivateAlbumRequest,
} from "@/data/dto/private-room";

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

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

export class PrivateRoomApi {
  async getAlbums(
    input: GetPrivateAlbumsInput = {},
  ): Promise<PrivateAlbumsResponse> {
    const env = await httpClient<ApiEnvelope<unknown>>(
      ApiPath.privateRoomAlbums,
      {
        query: {
          character: input.character ?? "elio",
          limit: input.limit ?? 20,
        },
      },
    );
    return PrivateAlbumsResponse.fromJson(unwrap(env));
  }

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

export const privateRoomApi = new PrivateRoomApi();
