import { z } from "zod";
import { MEASUREMENT_SYSTEMS, TEMPERATURE_UNITS } from "@app/shared-types";

/** i18n-spec §6: alla fält oberoende och valfria vid uppdatering. */
export const updateLocalePreferencesInputSchema = z.object({
  languageTag: z
    .string()
    .regex(/^[a-z]{2,3}(-[A-Za-z]{2,4})?(-[A-Za-z0-9]{2,8})?$/, "Ogiltig BCP 47-tagg")
    .optional(),
  regionCode: z
    .string()
    .regex(/^[A-Za-z]{2}$/, "Ogiltig ISO 3166-1 alpha-2-kod")
    .transform((v) => v.toUpperCase())
    .optional(),
  timeZone: z.string().min(1).max(64).optional(),
  measurementSystem: z.enum(MEASUREMENT_SYSTEMS).optional(),
  temperatureUnit: z.enum(TEMPERATURE_UNITS).optional(),
  currencyCode: z
    .string()
    .regex(/^[A-Za-z]{3}$/, "Ogiltig ISO 4217-kod")
    .transform((v) => v.toUpperCase())
    .optional(),
  firstDayOfWeek: z.number().int().min(0).max(6).optional(),
  use24HourTime: z.boolean().optional(),
});
export type UpdateLocalePreferencesInput = z.infer<typeof updateLocalePreferencesInputSchema>;
