import { z } from 'zod';

// ── IP Rule Types ────────────────────────────────────────────

export type IPAction = 'allow' | 'deny';

export interface IPRuleDoc {
  id: string;
  productId: string;
  ip: string;
  action: IPAction;
  reason: string;
  createdBy: string;
  createdAt: string;
  expiresAt?: string;
  _ts?: number;
}

// ── Schemas ──────────────────────────────────────────────────

export const CreateIPRuleSchema = z.object({
  ip: z.string().min(1).max(45),
  action: z.enum(['allow', 'deny']),
  reason: z.string().min(1).max(500),
  expiresAt: z.string().datetime().optional(),
});

export type CreateIPRuleInput = z.infer<typeof CreateIPRuleSchema>;

// ── Rate Limit Stats ─────────────────────────────────────────

export interface RateLimitStats {
  total429s: number;
  topKeys: Array<{ key: string; count: number; lastAt: string }>;
  windowStart: string;
}
