import { z } from "zod";
import type { IConsent } from "../consent.interface";

export const grantHandlerInputSchema = z
  .object({
    category: z.string().min(1),
    meta: z
      .object({
        bannerVersion: z.string().optional(),
        policyVersion: z.string().optional(),
        method: z.string().optional(),
      })
      .strict()
      .optional(),
  })
  .strict();

export type GrantHandlerInput = z.infer<typeof grantHandlerInputSchema>;

export async function grantHandler(
  consent: IConsent,
  input: GrantHandlerInput,
): Promise<{ success: true }> {
  await consent.grant(input.category, input.meta);
  return { success: true };
}
