import { z } from "zod"

import { nullableArrayObjectValidator } from "@/utils/zod/arrayValidator"
import { nullableNumberValidator } from "@/utils/zod/numberValidator"
import { nullableStringValidator } from "@/utils/zod/stringValidator"

const periodSchema = z.object({
  amount: nullableNumberValidator,
  endTime: nullableStringValidator,
  period: nullableStringValidator,
  startTime: nullableStringValidator,
})

const currencySchema = z
  .object({
    currency: nullableStringValidator,
    ordinary: nullableArrayObjectValidator(periodSchema),
    range: z
      .object({
        min: nullableNumberValidator,
        max: nullableNumberValidator,
      })
      .nullish(),
    weekend: nullableArrayObjectValidator(periodSchema),
  })
  .nullish()

const pricingSchema = z.object({
  freeParking: z.boolean(),
  localCurrency: currencySchema,
  paymentType: nullableStringValidator,
  requestedCurrency: currencySchema,
})

export const parkingSchema = z.object({
  address: nullableStringValidator,
  canMakeReservation: z.boolean(),
  distanceToHotel: nullableNumberValidator,
  externalParkingUrl: nullableStringValidator,
  name: nullableStringValidator,
  numberOfChargingSpaces: nullableNumberValidator,
  numberOfParkingSpots: nullableNumberValidator,
  pricing: pricingSchema,
  type: nullableStringValidator,
})
