import { z } from "zod";

const US_ZIP_REGEX = /^\d{5}(-\d{4})?$/;

export const addressLookupSchema = z.object({
  street: z.string().min(1, "请填写街道地址"),
  city: z.string().min(1, "请填写城市"),
  state: z.string().length(2, "请填写 2 位州码"),
  zip: z
    .string()
    .refine((v) => v === "" || US_ZIP_REGEX.test(v), "邮编格式无效")
    .default(""),
});

export const mothershipCandidatesBodySchema = z.object({
  customer_id: z.string().min(1, "请填写客户标识"),
  pickup_address: addressLookupSchema,
  delivery_address: addressLookupSchema,
});

/** 登录后一级：单边键入联想 */
export const mothershipSuggestBodySchema = z.object({
  customer_id: z.string().min(1, "请填写客户标识"),
  query: z
    .string()
    .trim()
    .min(3, "请至少输入 3 个字符以搜索地址"),
});

export const quoteSessionActionSchema = z.object({
  customer_id: z.string().min(1, "请填写客户标识"),
  quote_session_id: z.string().uuid("会话标识无效"),
});

export const sessionAddressConfirmSchema = z.object({
  customer_id: z.string().min(1, "请填写客户标识"),
  quote_session_id: z.string().uuid("会话标识无效"),
  pickup: z.object({
    option_id: z.string().min(1),
    display_label: z.string().min(1),
    formatted_address: z.string().min(1),
    street: z.string().min(1),
    city: z.string().min(1),
    state: z.string().length(2),
    zip: z.string(),
  }),
  delivery: z.object({
    option_id: z.string().min(1),
    display_label: z.string().min(1),
    formatted_address: z.string().min(1),
    street: z.string().min(1),
    city: z.string().min(1),
    state: z.string().length(2),
    zip: z.string(),
  }),
});
