// Addigy API Types

export interface AddigyConfig {
  apiUrl: string;
  apiToken: string;
  organizationId?: string; // Parent organization ID if needed
}

export interface PaginationParams {
  page?: number;
  limit?: number;
}

export interface FilterOperation {
  audit_field: string;
  type: 'string' | 'list' | 'number' | 'boolean' | 'date';
  operation: 'equals' | 'contains' | 'greater_than' | 'less_than' | 'in' | 'not_in';
  value: string | number | boolean | string[] | number[];
}

export interface QueryParams {
  filters?: FilterOperation[];
  page?: number;
  limit?: number;
}

export interface AddigyDevice {
  agentid: string;
  'Device Name': string;
  'Device Model Name': string;
  'MAC OS X Version'?: string;
  'iOS Version'?: string;
  'Processor Type'?: string;
  'Processor Speed (GHz)'?: number;
  'Total Disk Space (GB)'?: number;
  'Free Disk Space (GB)'?: number;
  'Free Disk Percentage'?: number;
  'Battery Percentage'?: number;
  'Battery Charging'?: boolean;
  'Battery Capacity Loss Percentage'?: number;
  'Current User'?: string;
  'Serial Number'?: string;
  'Displays Serial Number'?: string[];
  'Agent Version': string;
  policy_id: string;
  online: boolean;
  'Firewall Enabled'?: boolean;
  'FileVault Enabled'?: boolean;
  'Remote Login Enabled'?: boolean;
  'XCode Installed'?: boolean;
  'SMART Failing'?: boolean;
  'Has Wireless'?: boolean;
  Timezone?: string;
  'Warranty Expiration Date'?: string;
  'Warranty Days Left'?: number;
  'TeamViewer Client Id'?: string;
  'Crashplan Days Since Last Backup'?: number;
  'Last Check In'?: string;
  // Additional fields from device audits
  [key: string]: string | number | boolean | string[] | undefined;
}

export interface AddigyPolicy {
  policyId: string;
  orgid: string;
  name: string;
  parent?: string | null;
  color?: string;
  icon?: string;
  download_path?: string;
  agent_path?: string;
  last_deployed?: string;
  creation_time?: number;
  agent_version?: string;
  ignore_updates?: boolean;
  instructions?: any[];
  vnc_settings?: any;
  splashtop_settings?: any;
  ssh_settings?: any;
  system_updates_settings?: any;
  collector_settings?: any;
  prebuilt_app_settings?: any;
}

export interface AddigyOrganization {
  orgid: string;
  name: string;
  parent_org_id?: string;
  domain?: string;
  created_at?: string;
}

export interface AddigyApplication {
  name: string;
  version: string;
  path: string;
  bundle_id?: string;
  installed_date?: string;
}

export interface AddigyDeviceWithApps {
  agentid: string;
  'Device Name': string;
  'Device Model Name': string;
  'MAC OS X Version'?: string;
  'iOS Version'?: string;
  'Agent Version': string;
  policy_id: string;
  online: boolean;
  'Serial Number'?: string;
  'Current User'?: string;
  'Free Disk Percentage'?: number;
  'Battery Percentage'?: number;
  'Firewall Enabled'?: boolean;
  'FileVault Enabled'?: boolean;
  installed_applications?: AddigyApplication[];
  [key: string]: string | number | boolean | string[] | AddigyApplication[] | undefined;
}

export interface AddigyAlert {
  id: string;
  device_id: string;
  alert_type: string;
  severity: 'critical' | 'warning' | 'info';
  message: string;
  created_at: string;
  resolved: boolean;
  resolved_at?: string;
}

export interface AddigyMaintenanceItem {
  id: string;
  name: string;
  description?: string;
  policy_id?: string;
  enabled: boolean;
  schedule?: string;
  last_run?: string;
  next_run?: string;
}

export interface AddigyMonitoringItem {
  id: string;
  name: string;
  description?: string;
  policy_id?: string;
  enabled: boolean;
  condition: string;
  alert_level: 'critical' | 'warning' | 'info';
}

export interface AddigyCustomFact {
  id: string;
  name: string;
  value: string | number | boolean;
  device_id: string;
  created_at: string;
  updated_at: string;
}

export interface AddigySoftwareItem {
  identifier: string;
  name: string;
  version?: string;
  versions?: string[];
  category?: string;
  description?: string;
  install_type?: string;
}

export interface AddigyVariable {
  id: string;
  name: string;
  value: string;
  policy_id?: string;
  device_id?: string;
  description?: string;
}

export interface AddigyApiResponse<T> {
  data?: T;
  items?: T[];
  total?: number;
  page?: number;
  limit?: number;
  pages?: number;
}

export interface AddigyApiError {
  error: string;
  message: string;
  status_code?: number;
  details?: Record<string, unknown>;
}

// Enums for common values
export enum AddigyDeviceStatus {
  Online = 'online',
  Offline = 'offline',
}

export enum AddigyAlertSeverity {
  Critical = 'critical',
  Warning = 'warning',
  Info = 'info',
}

export enum AddigyDeviceType {
  Mac = 'mac',
  iPhone = 'iphone',
  iPad = 'ipad',
  AppleTV = 'appletv',
}

// Mapping types for Addigy organizations to Autotask companies
export interface AddigyOrgMapping {
  id: number;
  addigyOrgId: string;
  addigyOrgName: string;
  autotaskCompanyId: number;
  autotaskCompanyName: string;
  createdAt: string;
  updatedAt: string;
}
