import { InputParseError } from "../../entities/errors/common";
import {
  signOutInputSchema,
  type ISignOutUseCase,
} from "../../application/use-cases/sign-out.use-case";

export type ISignOutController = ReturnType<typeof signOutController>;

export const signOutController =
  (signOutUseCase: ISignOutUseCase) =>
  async (input: unknown): Promise<void> => {
    const parsed = signOutInputSchema.safeParse(input);
    if (!parsed.success) {
      throw new InputParseError("Invalid sign-out input", { cause: parsed.error });
    }
    await signOutUseCase(parsed.data);
  };
