import { InputParseError } from "../../entities/errors/common";
import {
  getSiteSettingsInputSchema,
  type GetSiteSettingsOutput,
  type IGetSiteSettingsUseCase,
} from "../../application/use-cases/get-site-settings.use-case";

function presenter(value: GetSiteSettingsOutput) {
  return value;
}

export type IGetSiteSettingsController = ReturnType<typeof getSiteSettingsController>;

export const getSiteSettingsController =
  (getSiteSettingsUseCase: IGetSiteSettingsUseCase) =>
  async (input: unknown): Promise<ReturnType<typeof presenter>> => {
    const parsed = getSiteSettingsInputSchema.safeParse(input);
    if (!parsed.success) {
      throw new InputParseError("Invalid get-site-settings input", { cause: parsed.error });
    }
    const result = await getSiteSettingsUseCase(parsed.data);
    return presenter(result);
  };
