/**
 * Shared API types for Redirect Intelligence v2
 */

import { z } from 'zod';

// Base API response
export const ApiResponseSchema = z.object({
  success: z.boolean(),
  status: z.number(),
  data: z.any().optional(),
  error: z.string().optional(),
  message: z.string().optional(),
});

export type ApiResponse<T = any> = {
  success: boolean;
  status: number;
  data?: T;
  error?: string;
  message?: string;
};

// Legacy redirect result (for backward compatibility)
export const LegacyRedirectSchema = z.object({
  url: z.string(),
  timestamp: z.number(),
  isSSL: z.boolean(),
  duration: z.number().optional(),
  statusCode: z.number().optional(),
  statusText: z.string().optional(),
  metadata: z.any().optional(),
  responseBody: z.string().optional(),
  sslInfo: z.any().optional(),
  error: z.string().optional(),
  final: z.boolean().optional(),
});

export type LegacyRedirect = z.infer<typeof LegacyRedirectSchema>;

// Track request schemas
export const TrackRequestSchema = z.object({
  url: z.string().url(),
  method: z.enum(['GET', 'HEAD', 'POST']).default('GET'),
  userAgent: z.string().optional(),
});

export type TrackRequest = z.infer<typeof TrackRequestSchema>;

// Track response schema
export const TrackResponseSchema = z.object({
  url: z.string(),
  method: z.string(),
  redirectCount: z.number(),
  finalUrl: z.string(),
  finalStatusCode: z.number().optional(),
  redirects: z.array(LegacyRedirectSchema),
});

export type TrackResponse = z.infer<typeof TrackResponseSchema>;
