// ignore_for_file: constant_identifier_names

import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';

class DevicesCategoryModel {
  int? id;
  final String? name;
  final String? icon;

  bool? devicesStatus;
  final List<DeviceModel>? devices;

  final DeviceType? type;
  bool isSelected;

  DevicesCategoryModel(
      {this.isSelected = false,
      required this.type,
      required this.name,
      required this.icon,
      required this.devices}) {
    //sets the initial status of the devices
    if (devices != null) {
      if (devices!.isNotEmpty) {
        bool tempStatus = devices!.first.isOnline ?? false;
        for (var device in devices!) {
          if (device.isOnline != tempStatus) {
            devicesStatus = false;
            break;
          }
        }
        devicesStatus = tempStatus;
      }
    } else {
      devicesStatus = false;
    }
  }

  DevicesCategoryModel.fromJson(Map<String, dynamic> json)
      : name = json['groupName'],
        // id = json['groupId'],
        type = devicesTypesMap[json['groupName']] ?? DeviceType.Other,
        icon = deviceTypeIconMap[
                devicesTypesMap[json['groupName']] ?? DeviceType.Other] ??
            '',
        devices = [],
        isSelected = false;

  static List<DevicesCategoryModel> fromJsonList(List<dynamic> jsonList) {
    return jsonList.map((item) => DevicesCategoryModel.fromJson(item)).toList();
  }
}

Map<DeviceType, String> deviceTypeIconMap = {
  DeviceType.AC: Assets.assetsIconsAC,
  DeviceType.LightBulb: Assets.assetsIconsLight,
  DeviceType.DoorLock: Assets.assetsIconsDoorLock,
  DeviceType.Curtain: Assets.assetsIconsCurtain,
  DeviceType.Gateway: Assets.assetsIconsGateway,
  DeviceType.CeilingSensor: Assets.assetsIconsSensors,
  DeviceType.WallSensor: Assets.assetsIconsSensors,
  DeviceType.ThreeGang: Assets.assetsIconsGang,
  DeviceType.OneGang: Assets.oneGang,
  DeviceType.TwoGang: Assets.twoGang,
  DeviceType.WH: Assets.waterHeaterIcon,
  DeviceType.DS: Assets.doorSensorIcon,
  DeviceType.Other: Assets.assetsIconsAC,
  DeviceType.OneTouch: Assets.gang1touch,
  DeviceType.TowTouch: Assets.gang2touch,
  DeviceType.ThreeTouch: Assets.gang3touch,
  DeviceType.GarageDoor: Assets.garageIcon
};
