import { InputParseError } from "../../entities/errors/common";
import {
  deleteMediaInputSchema,
  type IDeleteMediaUseCase,
} from "../../application/use-cases/delete-media.use-case";

export type IDeleteMediaController = ReturnType<typeof deleteMediaController>;

export const deleteMediaController =
  (deleteMediaUseCase: IDeleteMediaUseCase) =>
  async (input: unknown): Promise<void> => {
    const parsed = deleteMediaInputSchema.safeParse(input);
    if (!parsed.success) {
      throw new InputParseError("Invalid delete-media input", { cause: parsed.error });
    }
    await deleteMediaUseCase(parsed.data);
  };
