/**
 * Cockroach Configuration
 * Viewports, browsers, safety guards, thresholds
 */

export interface Viewport {
  name: string;
  width: number;
  height: number;
  deviceScaleFactor?: number;
  isMobile: boolean;
  hasTouch: boolean;
}

export interface BrowserProfile {
  name: string;
  engine: 'chromium' | 'webkit' | 'firefox';
  userAgent?: string;
}

export const VIEWPORTS: Viewport[] = [
  // iPhone 14 Pro
  { name: 'iPhone-14-Pro', width: 390, height: 844, deviceScaleFactor: 3, isMobile: true, hasTouch: true },
  // iPhone 15 Pro Max
  { name: 'iPhone-15-Pro-Max', width: 430, height: 932, deviceScaleFactor: 3, isMobile: true, hasTouch: true },
  // Android standard
  { name: 'Android-360', width: 360, height: 800, deviceScaleFactor: 3, isMobile: true, hasTouch: true },
  // Android large (Pixel 7 / Galaxy S23)
  { name: 'Android-412', width: 412, height: 915, deviceScaleFactor: 2.625, isMobile: true, hasTouch: true },
];

export const BROWSER_PROFILES_FULL: BrowserProfile[] = [
  { name: 'Safari-iOS', engine: 'webkit' },
  { name: 'Chrome-Android', engine: 'chromium' },
  { name: 'Chrome-iOS', engine: 'webkit' },
  { name: 'DuckDuckGo-iOS', engine: 'webkit' },
  { name: 'DuckDuckGo-Android', engine: 'chromium' },
];

// Quick mode: one engine per type
export const BROWSER_PROFILES_QUICK: BrowserProfile[] = [
  { name: 'Safari-iOS', engine: 'webkit' },
  { name: 'Chrome-Android', engine: 'chromium' },
];

export const BROWSER_PROFILES = BROWSER_PROFILES_QUICK;

// Crawl limits
export const MAX_DEPTH = 4;
export const MAX_ACTIONS = 200;
export const MAX_CLICKS_PER_ELEMENT = 2;
export const PAGE_TIMEOUT_MS = 15_000;
export const NETWORK_IDLE_TIMEOUT_MS = 5_000;
export const CLICK_DELAY_MS = 500;

// Safety: never click elements matching these selectors or text
export const DESTRUCTIVE_SELECTORS = [
  '[data-destructive]',
  'button:has-text("Delete")',
  'button:has-text("Remove Account")',
  'button:has-text("Confirm Purchase")',
  'button:has-text("Complete Payment")',
  'button:has-text("Pay Now")',
];

export const DESTRUCTIVE_TEXT_PATTERNS = [
  /delete\s+account/i,
  /confirm\s+purchase/i,
  /complete\s+payment/i,
  /pay\s+now/i,
  /place\s+order/i,
];

// URLs to skip (external, payment processors)
export const SKIP_URL_PATTERNS = [
  /stripe\.com/,
  /checkout\.stripe/,
  /accounts\.google/,
  /apple\.com\/sign/,
  /facebook\.com/,
  /twitter\.com/,
  /x\.com/,
  /instagram\.com/,
  /mailto:/,
  /tel:/,
];

// Bug severity thresholds
export const SLOW_ENDPOINT_MS = 3000;

// Priority routes to test (logged-out)
export const PRIORITY_ROUTES = [
  '/',
  '/forecast',
  '/rain-wire',
  '/performance',
  '/signup',
  '/login',
];

export interface CockroachOptions {
  baseUrl: string;
  loggedOutOnly: boolean;
  fullCrawl: boolean;
  mobileOnly: boolean;
  maxActions: number;
  maxDepth: number;
  outputDir: string;
  screenshotDir: string;
  tracing: boolean;
  headless: boolean;
}

export const DEFAULT_OPTIONS: CockroachOptions = {
  baseUrl: 'https://rainmakersports.app',
  loggedOutOnly: true,
  fullCrawl: false,
  mobileOnly: true,
  maxActions: MAX_ACTIONS,
  maxDepth: MAX_DEPTH,
  outputDir: './reports',
  screenshotDir: './screenshots',
  tracing: true,
  headless: true,
};
