import { z } from "zod";

import { HeaderNotFoundError } from "../../entities/errors/header";
import { headerSchema } from "../../entities/models/header";
import type { IHeaderRepository } from "../repositories/header.repository.interface";

// ── Input ────────────────────────────────────────────────────────────────
export const getHeaderInputSchema = z.object({}).strict();
export type GetHeaderInput = z.infer<typeof getHeaderInputSchema>;

// ── Output ───────────────────────────────────────────────────────────────
export const getHeaderOutputSchema = headerSchema;
export type GetHeaderOutput = z.infer<typeof getHeaderOutputSchema>;

// ── Use case ─────────────────────────────────────────────────────────────
export type IGetHeaderUseCase = ReturnType<typeof getHeaderUseCase>;

export const getHeaderUseCase =
  (headerRepository: IHeaderRepository) =>
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  async (_input: GetHeaderInput): Promise<GetHeaderOutput> => {
    const header = await headerRepository.getHeader();
    if (!header) {
      throw new HeaderNotFoundError("Header global not found");
    }
    return getHeaderOutputSchema.parse(header);
  };
