import type { TBroadlinkDeviceType } from './broadlink.types.js';

export const broadlinkDomain = 'broadlink';
export const broadlinkDefaultPort = 80;
export const broadlinkDefaultTimeoutSeconds = 5;
export const broadlinkDefaultDelaySeconds = 0.4;
export const broadlinkIrTickUs = 32.84;

export const broadlinkMacPrefixes = [
  '34ea34',
  '24dfa7',
  'a043b0',
  'b4430d',
  'c8f742',
  'e81656',
  'e87072',
  'ec0bae',
  '780f77',
];

export const broadlinkRemoteTypes = new Set<TBroadlinkDeviceType>(['RM4MINI', 'RM4PRO', 'RMMINI', 'RMMINIB', 'RMPRO']);
export const broadlinkRfRemoteTypes = new Set<TBroadlinkDeviceType>(['RM4PRO', 'RMPRO']);
export const broadlinkSwitchTypes = new Set<TBroadlinkDeviceType>(['BG1', 'MP1', 'MP1S', 'SP1', 'SP2', 'SP2S', 'SP3', 'SP3S', 'SP4', 'SP4B']);
export const broadlinkSensorTypes = new Set<TBroadlinkDeviceType>(['A1', 'A2', 'MP1S', 'RM4MINI', 'RM4PRO', 'RMPRO', 'SP2S', 'SP3S', 'SP4', 'SP4B']);

export const broadlinkSupportedTypes = new Set<TBroadlinkDeviceType>([
  ...broadlinkRemoteTypes,
  ...broadlinkSwitchTypes,
  ...broadlinkSensorTypes,
  'HYS',
  'LB1',
  'LB2',
]);

export const broadlinkSensorDescriptions: Record<string, { name: string; unit?: string; deviceClass?: string; stateClass?: string }> = {
  air_quality: { name: 'Air quality', deviceClass: 'aqi' },
  current: { name: 'Current', unit: 'A', deviceClass: 'current', stateClass: 'measurement' },
  humidity: { name: 'Humidity', unit: '%', deviceClass: 'humidity', stateClass: 'measurement' },
  light: { name: 'Light' },
  noise: { name: 'Noise' },
  overload: { name: 'Overload', unit: 'A', deviceClass: 'current', stateClass: 'measurement' },
  pm1: { name: 'PM1', unit: 'µg/m³', deviceClass: 'pm1', stateClass: 'measurement' },
  pm10: { name: 'PM10', unit: 'µg/m³', deviceClass: 'pm10', stateClass: 'measurement' },
  pm2_5: { name: 'PM2.5', unit: 'µg/m³', deviceClass: 'pm25', stateClass: 'measurement' },
  power: { name: 'Power', unit: 'W', deviceClass: 'power', stateClass: 'measurement' },
  temperature: { name: 'Temperature', unit: '°C', deviceClass: 'temperature', stateClass: 'measurement' },
  totalconsum: { name: 'Total consumption', unit: 'kWh', deviceClass: 'energy', stateClass: 'total_increasing' },
  volt: { name: 'Voltage', unit: 'V', deviceClass: 'voltage', stateClass: 'measurement' },
};
