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

export const homeworksDomain = 'homeworks';
export const homeworksDefaultName = 'Lutron Homeworks';

export type THomeworksRawData = TSimpleLocalRawData;
export interface IHomeworksSnapshot extends ISimpleLocalSnapshot {}
export interface IHomeworksButtonConfig {
  name?: string;
  number: number;
  led?: boolean;
  releaseDelay?: number;
}
export interface IHomeworksKeypadConfig {
  name?: string;
  addr: string;
  buttons?: IHomeworksButtonConfig[];
}
export interface IHomeworksDimmerConfig {
  name?: string;
  addr: string;
  rate?: number;
}
export interface IHomeworksConfig extends ISimpleLocalConfig {
  controllerId?: string;
  dimmers?: IHomeworksDimmerConfig[];
  keypads?: IHomeworksKeypadConfig[];
}
export interface IHomeAssistantHomeworksConfig extends IHomeworksConfig {}

const homeworksControlServices = [
  'send_command',
  'press',
  'turn_off',
  'turn_on',
];

export const homeworksProfile: ISimpleLocalIntegrationProfile = {
  domain: 'homeworks',
  displayName: 'Lutron Homeworks',
  manufacturer: 'Lutron',
  model: 'Homeworks controller',
  defaultName: homeworksDefaultName,
  defaultProtocol: 'tcp',
  status: 'read-only-runtime',
  platforms: [
    'binary_sensor',
    'button',
    'light',
  ],
  serviceDomains: [
    'button',
    'light',
  ],
  controlServices: homeworksControlServices,
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    'homeworks',
    'lutron homeworks',
    'pyhomeworks',
    'keypad',
    'dimmer',
  ],
  metadata: {
    source: 'home-assistant/core',
    upstreamPath: 'homeassistant/components/homeworks',
    upstreamDomain: 'homeworks',
    integrationType: 'hub',
    iotClass: 'local_push',
    qualityScale: undefined,
    requirements: [
      'pyhomeworks==1.1.2',
    ],
    dependencies: [],
    afterDependencies: [],
    codeowners: [],
    configFlow: true,
    documentation: 'https://www.home-assistant.io/integrations/homeworks',
    loggers: [
      'pyhomeworks',
    ],
    defaults: {
      lightName: 'Homeworks light',
      keypadName: 'Homeworks keypad',
      buttonName: 'Homeworks button',
      fadeRate: 1.0,
      buttonReleaseDelay: 0,
    },
    platforms: [
      'binary_sensor',
      'button',
      'light',
    ],
    events: [
      'homeworks_button_press',
      'homeworks_button_release',
    ],
    runtime: {
      type: 'read-only-runtime',
      services: [
        'snapshot',
        'status',
        'refresh',
        ...homeworksControlServices,
      ],
      platforms: [
        'binary_sensor',
        'button',
        'light',
      ],
      controls: 'delegated only to an injected client.execute or commandExecutor',
    },
    localApi: {
      implemented: [
        'manual local setup for controller, keypad, dimmer, snapshot, raw data, snapshotProvider, and injected native clients',
        'runtime device and entity mapping for light dimmers, keypad LED binary sensors, and keypad buttons',
        'safe command, light, and button service delegation to injected client.execute or commandExecutor only',
      ],
      explicitUnsupported: [
        'native pyhomeworks TCP login, callbacks, and polling in this TypeScript package',
        'claiming send_command, dimmer, or keypad button success without an injected client.execute or commandExecutor',
        'Home Assistant schema options menu for editing keypads and dimmers',
      ],
    },
  },
};
