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

export const fivemDomain = 'fivem';
export const fivemDefaultName = 'FiveM';
export const fivemDefaultPort = 30120;
export const fivemDefaultHttpPath = '/dynamic.json';

export type TFivemRawData = TSimpleLocalRawData;
export interface IFivemSnapshot extends ISimpleLocalSnapshot {}
export interface IFivemConfig extends ISimpleLocalConfig {
  gameName?: string;
}
export interface IHomeAssistantFivemConfig extends IFivemConfig {}

export const fivemProfile: ISimpleLocalIntegrationProfile = {
  domain: 'fivem',
  displayName: 'FiveM',
  manufacturer: 'Cfx.re',
  model: 'FXServer',
  defaultName: fivemDefaultName,
  defaultPort: fivemDefaultPort,
  defaultHttpPath: fivemDefaultHttpPath,
  defaultProtocol: 'http',
  status: 'read-only-runtime',
  platforms: [
    'binary_sensor',
    'sensor',
  ],
  serviceDomains: [],
  controlServices: [],
  discoverySources: [
    'manual',
    'http',
    'custom',
  ],
  discoveryKeywords: [
    'fivem',
    'fxserver',
    'cfx.re',
    'gta5',
    'players',
    'resources',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/fivem',
    upstreamDomain: 'fivem',
    integrationType: 'service',
    iotClass: 'local_polling',
    qualityScale: undefined,
    requirements: [
      'fivem-api==0.1.2',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [
      '@Sander0542',
    ],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/fivem',
    defaults: {
      port: fivemDefaultPort,
      httpPath: fivemDefaultHttpPath,
      scanIntervalSeconds: 60,
    },
    platforms: [
      'binary_sensor',
      'sensor',
    ],
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
      ],
      platforms: [
        'binary_sensor',
        'sensor',
      ],
      controls: false,
    },
    localApi: {
      implemented: [
        'manual local setup for FiveM host, port, snapshots, raw data, snapshotProvider, and injected native clients',
        'generic HTTP local snapshot transport for FXServer JSON endpoints such as dynamic.json when config.path is provided',
        'runtime device and entity mapping for status, players, and resources snapshots',
      ],
      explicitUnsupported: [
        'RCon/server command execution without an injected client.execute or commandExecutor',
        'claiming live command success without an injected client.execute or commandExecutor',
        'live gamename validation when no reachable local endpoint or injected client is configured',
      ],
    },
  },
};
