import { z } from "zod";
function truncateToMinute(date) {
  const truncated = new Date(date);
  truncated.setSeconds(0, 0);
  return truncated;
}
const currencyCodeSchema = z.string().trim().toUpperCase().regex(/^[A-Z]{3}$/, "Currency code must be a three-letter ISO code (e.g., USD, EUR)");
const sourceSchema = z.string().min(2, { message: "sourceTooShort" }).max(50, { message: "sourceTooLong" }).regex(/^[a-zA-Z0-9\s\-_]+$/, { message: "sourceInvalidFormat" }).transform((s) => s.trim());
const rateTypeSchema = z.enum(["buy", "sell"]).nullable().optional();
const currencyCreateSchema = z.object({
  organizationId: z.uuid(),
  tenantId: z.uuid(),
  code: currencyCodeSchema,
  name: z.string().min(1).max(200),
  symbol: z.string().max(10).nullable().optional(),
  decimalPlaces: z.number().int().min(0).max(8).optional(),
  thousandsSeparator: z.string().max(5).nullable().optional(),
  decimalSeparator: z.string().max(5).nullable().optional(),
  isBase: z.boolean().optional(),
  isActive: z.boolean().optional()
});
const currencyUpdateSchema = z.object({
  id: z.uuid(),
  organizationId: z.uuid().optional(),
  tenantId: z.uuid().optional(),
  code: currencyCodeSchema.optional(),
  name: z.string().min(1).max(200).optional(),
  symbol: z.string().max(10).nullable().optional(),
  decimalPlaces: z.number().int().min(0).max(8).optional(),
  thousandsSeparator: z.string().max(5).nullable().optional(),
  decimalSeparator: z.string().max(5).nullable().optional(),
  isBase: z.boolean().optional(),
  isActive: z.boolean().optional()
});
const currencyDeleteSchema = z.object({
  id: z.uuid(),
  organizationId: z.uuid(),
  tenantId: z.uuid()
});
const exchangeRateCreateSchema = z.object({
  organizationId: z.uuid(),
  tenantId: z.uuid(),
  fromCurrencyCode: currencyCodeSchema,
  toCurrencyCode: currencyCodeSchema,
  rate: z.string().regex(/^\d+(\.\d{1,8})?$/, "Rate must be a positive decimal number"),
  date: z.coerce.date().transform(truncateToMinute),
  source: sourceSchema,
  type: rateTypeSchema,
  isActive: z.boolean().optional()
}).refine((data) => data.fromCurrencyCode !== data.toCurrencyCode, {
  message: "From and To currencies must be different",
  path: ["toCurrencyCode"]
}).refine((data) => parseFloat(data.rate) > 0, {
  message: "Rate must be greater than zero",
  path: ["rate"]
});
const exchangeRateUpdateSchema = z.object({
  id: z.uuid(),
  organizationId: z.uuid().optional(),
  tenantId: z.uuid().optional(),
  fromCurrencyCode: currencyCodeSchema.optional(),
  toCurrencyCode: currencyCodeSchema.optional(),
  rate: z.string().regex(/^\d+(\.\d{1,8})?$/).optional(),
  date: z.coerce.date().transform(truncateToMinute).optional(),
  source: sourceSchema.optional(),
  type: rateTypeSchema,
  isActive: z.boolean().optional()
}).refine(
  (data) => {
    if (data.fromCurrencyCode && data.toCurrencyCode) {
      return data.fromCurrencyCode !== data.toCurrencyCode;
    }
    return true;
  },
  {
    message: "From and To currencies must be different",
    path: ["toCurrencyCode"]
  }
).refine(
  (data) => {
    if (data.rate) {
      return parseFloat(data.rate) > 0;
    }
    return true;
  },
  {
    message: "Rate must be greater than zero",
    path: ["rate"]
  }
);
const exchangeRateDeleteSchema = z.object({
  id: z.uuid(),
  organizationId: z.uuid(),
  tenantId: z.uuid()
});
const providerSchema = z.enum(["NBP", "Raiffeisen Bank Polska", "Custom"]);
const syncTimeSchema = z.string().regex(/^([01]\d|2[0-3]):([0-5]\d)$/, "Invalid time format. Use HH:MM").nullable();
const currencyFetchConfigCreateSchema = z.object({
  provider: providerSchema,
  isEnabled: z.boolean().default(false),
  syncTime: syncTimeSchema.optional(),
  config: z.record(z.string(), z.unknown()).nullable().optional()
});
const currencyFetchConfigUpdateSchema = z.object({
  isEnabled: z.boolean().optional(),
  syncTime: syncTimeSchema.optional(),
  config: z.record(z.string(), z.unknown()).nullable().optional()
});
export {
  currencyCreateSchema,
  currencyDeleteSchema,
  currencyFetchConfigCreateSchema,
  currencyFetchConfigUpdateSchema,
  currencyUpdateSchema,
  exchangeRateCreateSchema,
  exchangeRateDeleteSchema,
  exchangeRateUpdateSchema,
  providerSchema,
  syncTimeSchema,
  truncateToMinute
};
//# sourceMappingURL=validators.js.map
