import { InputParseError } from "../../entities/errors/common";
import {
  get{{pascalCase entity}}InputSchema,
  type Get{{pascalCase entity}}Output,
  type IGet{{pascalCase entity}}UseCase,
} from "../../application/use-cases/get-{{kebabCase entity}}.use-case";

function presenter(value: Get{{pascalCase entity}}Output) {
  return value;
}

export type IGet{{pascalCase entity}}Controller = ReturnType<typeof get{{pascalCase entity}}Controller>;

export const get{{pascalCase entity}}Controller =
  (get{{pascalCase entity}}UseCase: IGet{{pascalCase entity}}UseCase) =>
  async (input: unknown): Promise<ReturnType<typeof presenter>> => {
    const parsed = get{{pascalCase entity}}InputSchema.safeParse(input);
    if (!parsed.success) {
      throw new InputParseError("Invalid get-{{kebabCase entity}} input", { cause: parsed.error });
    }
    const result = await get{{pascalCase entity}}UseCase(parsed.data);
    return presenter(result);
  };
