/**
 * 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 PaymentIntentSchema = z.object({
  token: z.string().min(1, "Checkout token is required"),
  billing_address: AddressSchema.optional(),
  shipping_address: AddressSchema.nullable().optional(),
})

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

export const EasyShipWebhookSchema = z.object({
  event_type: z.enum([
    "shipment.tracking.statuschanged",
    "shipment.tracking.checkpointscreated",
    "shipment.label.created",
    "shipment.label.failed",
    "shipment.cancelled",
  ]),
  easyship_shipment_id: z.string(),
  platform_order_number: z.string().optional(),
  tracking_number: z.string().optional(),
  tracking_status: z.string().optional(),
  courier_name: 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 EasyShipWebhookPayload = z.infer<typeof EasyShipWebhookSchema>
