import type { ToolInput } from "../../core/io/input-types";
import type { ToolResult } from "../../core/io/output-types";
import type { ToolContext } from "../../core/plugins/plugin-types";
import type { PdfWatermarkOptions } from "./index";
import { applyWatermark } from "./watermark";

export async function runPdfWatermark(
  input: ToolInput,
  options: PdfWatermarkOptions,
  context: ToolContext
): Promise<ToolResult> {
  const files = input.files;

  if (!files || !Array.isArray(files) || files.length === 0) {
    throw new Error("No PDF file provided.");
  }

  const file = files[0];
  const buffer = await file.arrayBuffer();

  return applyWatermark(file.name, buffer, options, context.reportProgress);
}
