import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
import { z } from "zod";
import { logConfigInvalid } from "./security-logger.js";
const PromptOptionSchema = z.object({
  key: z.string().max(10),
  label: z.string().max(200),
  action: z.string().max(500).optional()
});
const PendingPromptSchema = z.object({
  id: z.string().max(32),
  timestamp: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/)),
  message: z.string().max(1e3),
  options: z.array(PromptOptionSchema).max(10),
  type: z.enum(["options", "yesno", "freeform"]),
  callback: z.string().max(500).optional(),
  expiresAt: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/))
});
const NotifyOnSchema = z.object({
  taskComplete: z.boolean(),
  reviewReady: z.boolean(),
  error: z.boolean(),
  custom: z.boolean()
});
const QuietHoursSchema = z.object({
  enabled: z.boolean(),
  start: z.string().regex(/^\d{2}:\d{2}$/),
  end: z.string().regex(/^\d{2}:\d{2}$/)
});
const SMSConfigSchema = z.object({
  enabled: z.boolean(),
  channel: z.enum(["whatsapp", "sms"]),
  accountSid: z.string().max(100).optional(),
  authToken: z.string().max(100).optional(),
  smsFromNumber: z.string().max(20).optional(),
  smsToNumber: z.string().max(20).optional(),
  whatsappFromNumber: z.string().max(30).optional(),
  whatsappToNumber: z.string().max(30).optional(),
  fromNumber: z.string().max(20).optional(),
  toNumber: z.string().max(20).optional(),
  webhookUrl: z.string().url().max(500).optional(),
  notifyOn: NotifyOnSchema,
  quietHours: QuietHoursSchema.optional(),
  responseTimeout: z.number().int().min(30).max(3600),
  pendingPrompts: z.array(PendingPromptSchema).max(100)
});
const PendingActionSchema = z.object({
  id: z.string().max(32),
  promptId: z.string().max(32),
  response: z.string().max(1e3),
  action: z.string().max(500),
  timestamp: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/)),
  status: z.enum(["pending", "running", "completed", "failed"]),
  result: z.string().max(1e4).optional(),
  error: z.string().max(1e3).optional()
});
const ActionQueueSchema = z.object({
  actions: z.array(PendingActionSchema).max(1e3),
  lastChecked: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/))
});
const AutoBackgroundConfigSchema = z.object({
  enabled: z.boolean(),
  timeoutMs: z.number().int().min(1e3).max(6e5),
  alwaysBackground: z.array(z.string().max(200)).max(100),
  neverBackground: z.array(z.string().max(200)).max(100),
  verbose: z.boolean().optional()
});
function parseConfigSafe(schema, data, defaultValue, configName) {
  const result = schema.safeParse(data);
  if (result.success) {
    return result.data;
  }
  const errors = result.error.issues.map(
    (i) => `${i.path.join(".")}: ${i.message}`
  );
  logConfigInvalid(configName, errors);
  console.error(`[hooks] Invalid ${configName} config:`, errors.join(", "));
  return defaultValue;
}
export {
  ActionQueueSchema,
  AutoBackgroundConfigSchema,
  NotifyOnSchema,
  PendingActionSchema,
  PendingPromptSchema,
  PromptOptionSchema,
  QuietHoursSchema,
  SMSConfigSchema,
  parseConfigSafe
};
//# sourceMappingURL=schemas.js.map
