// ═══════════════════════════════════════════════════════════
// SLA Constants — from CONTRACTS.md §5.3, Appendix B
// ═══════════════════════════════════════════════════════════

import type { Priority } from "../types/pipeline.js";

/** Default SLA deadlines by priority (in seconds) */
export const DEFAULT_SLA: Record<Priority, number> = {
  critical: 3600,     // 1 hour
  high:     14400,    // 4 hours
  medium:   86400,    // 24 hours
  low:      259200,   // 72 hours
};

/** SLA warning threshold: warn at this percentage of time remaining */
export const SLA_WARNING_THRESHOLD_PERCENT = 25;

/** SLA escalation timeline (minutes after task creation) */
export const SLA_ESCALATION_TIMELINE = {
  /** First reminder */
  REMINDER_1_MINUTES: 30,
  /** Second reminder */
  REMINDER_2_MINUTES: 120,
  /** Auto-escalate after breach */
  AUTO_ESCALATE_AFTER_BREACH_MINUTES: 120,
} as const;

/** Notification channels by escalation level */
export const ESCALATION_CHANNELS: Record<number, string[]> = {
  0: ["dashboard"],
  1: ["dashboard", "discord"],
  2: ["dashboard", "discord", "push"],
  3: ["dashboard", "discord", "push", "sms"],
  4: ["dashboard", "discord", "push", "sms"],
};

/** Calculate SLA deadline from priority */
export function calcSlaDeadline(priority: Priority, fromDate?: Date): Date {
  const base = fromDate ?? new Date();
  return new Date(base.getTime() + DEFAULT_SLA[priority] * 1000);
}
