/**
 * Zod schemas for Web Push API routes.
 *
 * Used at the API boundary to validate all push-related inputs.
 */

import { z } from 'zod';

// ---------------------------------------------------------------------------
// Subscribe
// ---------------------------------------------------------------------------

export const subscribeBodySchema = z.object({
  endpoint: z
    .url('endpoint must be a valid URL')
    .refine((u) => new URL(u).protocol === 'https:', 'push endpoint must use HTTPS'),
  keys: z.object({
    p256dh: z.string().min(1, 'p256dh key is required'),
    auth: z.string().min(1, 'auth key is required'),
  }),
  userAgent: z.string().optional(),
});

export type SubscribeBody = z.infer<typeof subscribeBodySchema>;

// ---------------------------------------------------------------------------
// Unsubscribe
// ---------------------------------------------------------------------------

export const unsubscribeBodySchema = z.object({
  endpoint: z.url('endpoint must be a valid URL'),
});

export type UnsubscribeBody = z.infer<typeof unsubscribeBodySchema>;
