import type { TRflinkCoverType, TRflinkLightType } from './rflink.types.js';

export const rflinkDomain = 'rflink';
export const rflinkDefaultBaudRate = 57600;
export const rflinkDefaultReconnectInterval = 10;
export const rflinkDefaultTcpKeepaliveIdleTimer = 3600;
export const rflinkDefaultSignalRepetitions = 1;
export const rflinkDefaultWaitForAck = true;

export const rflinkSensorTypes: Record<string, { name: string; unit?: string; deviceClass?: string; stateClass?: string }> = {
  average_windspeed: { name: 'Average windspeed', unit: 'km/h', deviceClass: 'wind_speed', stateClass: 'measurement' },
  barometric_pressure: { name: 'Barometric pressure', unit: 'hPa', deviceClass: 'pressure', stateClass: 'measurement' },
  battery: { name: 'Battery' },
  co2_air_quality: { name: 'CO2 air quality', unit: 'ppm', deviceClass: 'co2', stateClass: 'measurement' },
  command: { name: 'Command' },
  current_phase_1: { name: 'Current phase 1', unit: 'A', deviceClass: 'current', stateClass: 'measurement' },
  current_phase_2: { name: 'Current phase 2', unit: 'A', deviceClass: 'current', stateClass: 'measurement' },
  current_phase_3: { name: 'Current phase 3', unit: 'A', deviceClass: 'current', stateClass: 'measurement' },
  distance: { name: 'Distance', unit: 'mm', deviceClass: 'distance', stateClass: 'measurement' },
  doorbell_melody: { name: 'Doorbell melody' },
  firmware: { name: 'Firmware' },
  hardware: { name: 'Hardware' },
  humidity: { name: 'Humidity', unit: '%', deviceClass: 'humidity', stateClass: 'measurement' },
  humidity_status: { name: 'Humidity status' },
  kilowatt: { name: 'Kilowatt', unit: 'kW', deviceClass: 'power', stateClass: 'measurement' },
  light_intensity: { name: 'Light intensity', unit: 'lux', deviceClass: 'illuminance', stateClass: 'measurement' },
  meter_value: { name: 'Meter value' },
  noise_level: { name: 'Noise level' },
  rain_rate: { name: 'Rain rate', unit: 'mm/h', deviceClass: 'precipitation_intensity', stateClass: 'measurement' },
  revision: { name: 'Revision' },
  temperature: { name: 'Temperature', unit: '°C', deviceClass: 'temperature', stateClass: 'measurement' },
  timestamp: { name: 'Timestamp', unit: 's' },
  total_rain: { name: 'Total rain', unit: 'mm', deviceClass: 'precipitation', stateClass: 'total_increasing' },
  update_time: { name: 'Update time', unit: 's' },
  uv_intensity: { name: 'UV intensity', stateClass: 'measurement' },
  version: { name: 'Version' },
  voltage: { name: 'Voltage', unit: 'V', deviceClass: 'voltage', stateClass: 'measurement' },
  watt: { name: 'Watt', unit: 'W', deviceClass: 'power', stateClass: 'measurement' },
  weather_forecast: { name: 'Weather forecast' },
  windchill: { name: 'Wind chill', unit: '°C', deviceClass: 'temperature', stateClass: 'measurement' },
  winddirection: { name: 'Wind direction', unit: '°', deviceClass: 'wind_direction', stateClass: 'measurement_angle' },
  windgusts: { name: 'Wind gusts', unit: 'km/h', deviceClass: 'wind_speed', stateClass: 'measurement' },
  windspeed: { name: 'Wind speed', unit: 'km/h', deviceClass: 'wind_speed', stateClass: 'measurement' },
  windtemp: { name: 'Wind temperature', unit: '°C', deviceClass: 'temperature', stateClass: 'measurement' },
};

export const rflinkPacketFieldAliases: Record<string, string> = {
  awinsp: 'average_windspeed',
  baro: 'barometric_pressure',
  bat: 'battery',
  bforecast: 'weather_forecast',
  chime: 'doorbell_melody',
  cmd: 'command',
  co2: 'co2_air_quality',
  current: 'current_phase_1',
  current2: 'current_phase_2',
  current3: 'current_phase_3',
  dist: 'distance',
  fw: 'firmware',
  hstatus: 'humidity_status',
  hum: 'humidity',
  hw: 'hardware',
  kwatt: 'kilowatt',
  lux: 'light_intensity',
  meter: 'meter_value',
  rain: 'total_rain',
  rainrate: 'rain_rate',
  raintot: 'total_rain',
  rev: 'revision',
  sound: 'noise_level',
  temp: 'temperature',
  uv: 'uv_intensity',
  ver: 'version',
  volt: 'voltage',
  watt: 'watt',
  winchl: 'windchill',
  wind: 'windspeed',
  windir: 'winddirection',
  wings: 'windgusts',
  winsp: 'windspeed',
  wintmp: 'windtemp',
};

export const rflinkPacketUnits: Record<string, string | undefined> = {
  awinsp: 'km/h',
  current: 'A',
  current2: 'A',
  current3: 'A',
  hum: '%',
  kwatt: 'kW',
  lux: 'lux',
  rain: 'mm',
  rainrate: 'mm',
  raintot: 'mm',
  temp: '°C',
  volt: 'V',
  watt: 'W',
  winchl: '°C',
  wind: 'km/h',
  windir: '°',
  wings: 'km/h',
  winsp: 'km/h',
  wintmp: '°C',
};

export const rflinkDefaultLightTypeByProtocol: Record<string, TRflinkLightType> = {
  newkaku: 'hybrid',
};

export const rflinkDefaultCoverTypeByProtocol: Record<string, TRflinkCoverType> = {
  newkaku: 'inverted',
};
