import type {
  FeedbackSubmitResponse,
  SubmitFeedbackInput,
} from "@/data/schemas/feedback";
import type { IFeedbackRepository } from "@/data/repositories/interfaces";
import { FeedbackApi, feedbackApi } from "@/data/services/api/feedback_api";
import { Result } from "@/utils/result";

import { createLazySingleton } from "./lazy_singleton";

export class FeedbackRepository implements IFeedbackRepository {
  constructor(private readonly api: FeedbackApi) {}

  submit(input: SubmitFeedbackInput): Promise<Result<FeedbackSubmitResponse>> {
    return Result.wrap(() => this.api.submit(input));
  }
}

export const getFeedbackRepository = createLazySingleton<IFeedbackRepository>(
  () => new FeedbackRepository(feedbackApi),
);
