// Datto RMM API Types

export interface DattoRMMConfig {
  apiUrl: string;
  apiKey: string;
  apiSecret: string;
}

export interface DattoRMMDevice {
  id: number;
  uid: string;
  siteId: number;
  siteUid: string;
  siteName: string;
  deviceType: {
    category: string;
    type: string;
  };
  hostname: string;
  description: string;
  intIpAddress: string;
  extIpAddress: string;
  macAddresses?: string[];
  domain: string;
  manufacturer?: string;
  model?: string;
  serialNumber?: string;
  lastSeen: number; // timestamp in milliseconds
  lastLoggedInUser?: string;
  lastReboot?: number;
  lastAuditDate?: number;
  creationDate?: number;
  online: boolean;
  suspended: boolean;
  deleted: boolean;
  rebootRequired?: boolean;
  a64Bit?: boolean;
  operatingSystem: string;
  cagVersion?: string;
  displayVersion?: string;
  memory?: number; // in MB
  cpuCores?: number;
  cpuName?: string;
  diskSize?: number; // in GB
  antivirus?: {
    antivirusProduct: string;
    antivirusStatus: string;
  };
  patchManagement?: {
    patchStatus: string;
    patchesApprovedPending: number;
    patchesNotApproved: number;
    patchesInstalled: number;
  };
  softwareStatus?: string;
  portalUrl?: string;
  webRemoteUrl?: string;
  warrantyDate?: string | null;
  snmpEnabled?: boolean;
  deviceClass?: string;
  udf?: Record<string, any>;
}

export interface DattoRMMSite {
  id: number;
  uid: string;
  accountUid?: string;
  name: string;
  description: string;
  notes: string | null;
  onDemand: boolean;
  splashtopAutoInstall?: boolean;
  proxySettings?: {
    host: string;
    port: number;
    username?: string;
  } | null;
  devicesStatus?: {
    numberOfDevices: number;
    numberOfOnlineDevices: number;
    numberOfOfflineDevices: number;
  };
  autotaskCompanyName?: string;
  autotaskCompanyId?: string;
  portalUrl?: string;
  devices?: DattoRMMDevice[];
}

export interface DattoRMMAlert {
  alertUid: string;
  priority: string;
  diagnostics: string | null;
  resolved: boolean;
  resolvedBy: string | null;
  resolvedOn: number | null;
  muted: boolean;
  ticketNumber: string | null;
  timestamp: number;
  alertMonitorInfo?: {
    sendsEmails: boolean;
    createsTicket: boolean;
  };
  alertContext?: {
    '@class': string;
    [key: string]: any;
  };
  alertSourceInfo?: {
    deviceUid: string;
    deviceName: string;
    siteUid: string;
    siteName: string;
  };
  responseActions?: Array<{
    actionTime: number;
    actionType: string;
    description: string;
    actionReference: string | null;
    actionReferenceInt: string | null;
  }> | null;
  autoresolveMins?: number;
}

export interface DattoRMMApiResponse<T> {
  items?: T[];
  item?: T;
  pageDetails?: {
    count: number;
    totalCount?: number;
    prevPageUrl: string | null;
    nextPageUrl: string | null;
  };
}

export interface DattoRMMError {
  error: string;
  message: string;
  code?: string;
}

export interface DeviceComparison {
  autotaskDevice?: any; // ConfigurationItem from Autotask
  rmmDevice?: DattoRMMDevice;
  status: 'matched' | 'autotask-only' | 'rmm-only' | 'mismatch';
  discrepancies?: {
    field: string;
    autotaskValue: any;
    rmmValue: any;
  }[];
}
