import type { ICharacterRepository } from "@/data/repositories/interfaces";
import type { CharacterListResponse } from "@/data/schemas/character";
import { CharacterApi, characterApi } from "@/data/services/api";
import { Result } from "@/utils/result";

import { createLazySingleton } from "./lazy_singleton";

export class CharacterRepository implements ICharacterRepository {
  constructor(private readonly api: CharacterApi) {}

  async getChatCharacters(): Promise<Result<CharacterListResponse>> {
    return Result.wrap(() => this.api.getChatCharacters());
  }
}

export const getCharacterRepository = createLazySingleton<ICharacterRepository>(
  () => new CharacterRepository(characterApi),
);
