import type { CheckResult as ApiCheckResult, CheckFailure } from "../../shared/api";

export interface CheckResult extends ApiCheckResult {
  targetId: string;
}

export interface DefaultsConfig {
  [checkerKey: string]: unknown;
  interval?: string;
  timeout?: string;
}

export interface EngineRuntimeConfig {
  maxConcurrentChecks?: number;
  retention?: string;
}

export type JsonValue = boolean | JsonValue[] | null | number | string | { [key: string]: JsonValue };

export interface ProbeConfig {
  defaults?: DefaultsConfig;
  runtime?: EngineRuntimeConfig;
  server?: ServerConfig;
  targets: RawTargetConfig[];
  variables?: Record<string, VariableValue>;
}

export interface RawTargetConfig {
  [configKey: string]: unknown;
  description?: null | string;
  expect?: unknown;
  group?: string;
  id: string;
  interval?: string;
  name?: null | string;
  timeout?: string;
  type: string;
}

export interface ResolvedTargetBase {
  [key: string]: unknown;
  description: null | string;
  expect?: unknown;
  group: string;
  id: string;
  intervalMs: number;
  name: null | string;
  rawExpect?: unknown;
  timeoutMs: number;
  type: string;
}

export interface ServerConfig {
  dataDir?: string;
  host?: string;
  port?: number;
}

export interface StoredCheckResult {
  duration_ms: null | number;
  failure: null | string;
  id: number;
  matched: number;
  observation: null | string;
  target_id: string;
  timestamp: string;
}

export interface StoredTarget {
  active: number;
  config: string;
  description: null | string;
  expect: null | string;
  grp: string;
  id: string;
  interval_ms: number;
  name: null | string;
  target: string;
  timeout_ms: number;
  type: string;
}

export type VariableValue = boolean | number | string;

export type { CheckFailure };
