import type { ISimpleLocalConfig, ISimpleLocalIntegrationProfile, ISimpleLocalSnapshot, TSimpleLocalRawData } from '../../core/index.js';

export const paperlessNgxDomain = "paperless_ngx";
export const paperlessNgxDefaultName = "Paperless-ngx";
export const paperlessNgxDefaultTimeoutMs = 10000;

export interface IPaperlessNgxRawApiData extends Record<string, unknown> {
  statistics?: Record<string, unknown>;
  status?: Record<string, unknown>;
  remoteVersion?: Record<string, unknown>;
  statusError?: string;
  remoteVersionError?: string;
  fetchedAt?: string;
}
export type TPaperlessNgxRawData = TSimpleLocalRawData | IPaperlessNgxRawApiData;
export interface IPaperlessNgxSnapshot extends ISimpleLocalSnapshot {}
export interface IPaperlessNgxConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
  verifySsl?: boolean;
}
export interface IHomeAssistantPaperlessNgxConfig extends IPaperlessNgxConfig {}

export const paperlessNgxProfile: ISimpleLocalIntegrationProfile = {
  domain: paperlessNgxDomain,
  displayName: "Paperless-ngx",
  manufacturer: "Paperless-ngx",
  model: "Paperless-ngx local integration",
  defaultName: paperlessNgxDefaultName,
  defaultProtocol: 'https',
  status: "read-only-runtime",
  platforms: [
    "sensor",
    "update",
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "paperless_ngx",
    "Paperless-ngx",
    "Paperless Ngx",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/paperless_ngx",
    "upstreamDomain": "paperless_ngx",
    "integrationType": "service",
    "iotClass": "local_polling",
    "qualityScale": "platinum",
    "requirements": [
      "pypaperless==4.1.1",
    ],
    "codeowners": [
      "@fvgarrel",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/paperless_ngx",
    "loggers": [
      "pypaperless",
    ],
    "runtime": {
      "type": "read-only-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
      ],
      "platforms": [
        "sensor",
        "update",
      ],
      "controls": false,
    },
    "localApi": {
      "implemented": [
        "native Paperless-ngx HTTP REST polling for /api/statistics/, /api/status/, and optional /api/remote_version/",
        "Token authentication using config.apiKey or config.token with Accept: application/json; version=7",
        "runtime mapping for Paperless-ngx statistics, diagnostics, and update metadata",
        "manual snapshots, rawData, snapshotProvider, and injected native clients remain supported",
      ],
      "explicitUnsupported": [
        "username/password token generation through /api/token/ is not performed; configure an existing Paperless-ngx API token",
        "custom CA/verify_ssl=false behavior cannot be reproduced with Node global fetch without adding dependencies",
        "Home Assistant entity registry migrations and repair flows",
      ],
    },
  },
};
