import { z } from "zod";

import { {{pascalCase entity}}NotFoundError } from "../../entities/errors/{{kebabCase entity}}";
import { {{camelCase entity}}Schema } from "../../entities/models/{{kebabCase entity}}";
import type { I{{pascalCase entity}}Repository } from "../repositories/{{kebabCase entity}}.repository.interface";

// ── Input ────────────────────────────────────────────────────────────────
export const get{{pascalCase entity}}InputSchema = z
  .object({
    id: z.string().min(1),
  })
  .strict();
export type Get{{pascalCase entity}}Input = z.infer<typeof get{{pascalCase entity}}InputSchema>;

// ── Output ───────────────────────────────────────────────────────────────
export const get{{pascalCase entity}}OutputSchema = {{camelCase entity}}Schema;
export type Get{{pascalCase entity}}Output = z.infer<typeof get{{pascalCase entity}}OutputSchema>;

// ── Use case ─────────────────────────────────────────────────────────────
export type IGet{{pascalCase entity}}UseCase = ReturnType<typeof get{{pascalCase entity}}UseCase>;

export const get{{pascalCase entity}}UseCase =
  ({{camelCase entity}}Repository: I{{pascalCase entity}}Repository) =>
  async (input: Get{{pascalCase entity}}Input): Promise<Get{{pascalCase entity}}Output> => {
    const result = await {{camelCase entity}}Repository.get{{pascalCase entity}}(input.id);
    if (!result) {
      throw new {{pascalCase entity}}NotFoundError(`{{pascalCase entity}} not found: ${input.id}`);
    }
    return get{{pascalCase entity}}OutputSchema.parse(result);
  };
