/**
 * Zod schemas for validation
 */

import { z } from "zod"

export const AddressSchema = z.object({
  first_name: z.string().min(1, "First name is required"),
  last_name: z.string().min(1, "Last name is required"),
  address_1: z.string().min(1, "Address is required"),
  address_2: z.string().optional(),
  city: z.string().min(1, "City is required"),
  state: z.string().min(1, "State is required"),
  postcode: z.string().min(1, "Postal code is required"),
  country: z.string().min(2, "Country is required").max(2),
})

export const CheckoutSessionSchema = z.object({
  token: z.string().min(1, "Checkout token is required"),
})

export const ContactInfoSchema = z.object({
  email: z.string().email("Valid email is required"),
  phone: z.string().min(1, "Phone number is required"),
})

export const PaymentIntentSchema = z.object({
  token: z.string().min(1, "Checkout token is required"),
  billing_address: AddressSchema.optional(),
  shipping_address: AddressSchema.nullable().optional(),
  contact_info: ContactInfoSchema.optional(),
})

export const PayPalCaptureSchema = z.object({
  token: z.string().min(1, "Checkout token is required"),
  paypal_order_id: z.string().min(1, "PayPal order ID is required"),
})

export const OrderStatusSchema = z.object({
  token: z.string().min(1, "Checkout token is required"),
})

export const FedExWebhookSchema = z.object({
  trackingNumber: z.string(),
  eventType: z.string(),
  eventDescription: z.string().optional(),
  eventTimestamp: z.string().optional(),
  statusCode: z.string().optional(),
})

export type Address = z.infer<typeof AddressSchema>
export type CheckoutSessionRequest = z.infer<typeof CheckoutSessionSchema>
export type PaymentIntentRequest = z.infer<typeof PaymentIntentSchema>
export type OrderStatusRequest = z.infer<typeof OrderStatusSchema>
export type FedExWebhookPayload = z.infer<typeof FedExWebhookSchema>
