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

export const gpsdDomain = 'gpsd';
export const gpsdDefaultName = 'GPS';
export const gpsdDefaultHost = '127.0.0.1';
export const gpsdDefaultPort = 2947;

export type TGpsdRawData = TSimpleLocalRawData;
export interface IGpsdSnapshot extends ISimpleLocalSnapshot {}
export interface IGpsdConfig extends ISimpleLocalConfig {
  host?: string;
  port?: number;
}
export interface IHomeAssistantGpsdConfig extends IGpsdConfig {}

export const gpsdProfile: ISimpleLocalIntegrationProfile = {
  domain: 'gpsd',
  displayName: 'GPSD',
  manufacturer: 'GPSD',
  model: 'GPS receiver',
  defaultName: gpsdDefaultName,
  defaultPort: gpsdDefaultPort,
  defaultTcpCommand: '?WATCH={"enable":true,"json":true}',
  defaultProtocol: 'tcp',
  status: 'read-only-runtime',
  platforms: [
    'sensor',
  ],
  serviceDomains: [
    'sensor',
  ],
  controlServices: [],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    'gpsd',
    'gps',
    'gps3',
    'gps receiver',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/gpsd',
    upstreamDomain: 'gpsd',
    iotClass: 'local_polling',
    qualityScale: undefined,
    requirements: [
      'gps3==0.33.3',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@fabaff',
      '@jrieger',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/gpsd',
    loggers: [
      'gps3',
    ],
    defaults: {
      host: gpsdDefaultHost,
      port: gpsdDefaultPort,
    },
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
      ],
      platforms: [
        'sensor',
      ],
      controls: false,
    },
    localApi: {
      implemented: [
        'manual local TCP endpoint metadata, snapshots, rawData, snapshotProvider, and injected native clients',
        'runtime mapping for GPSD mode, latitude, longitude, elevation, time, speed, climb, and satellite sensors',
      ],
      explicitUnsupported: [
        'claiming live command success without injected client.execute or commandExecutor',
        'long-running GPSD stream management beyond a single SimpleLocal TCP read without an injected client or snapshotProvider',
      ],
    },
  },
};
