import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
import 'package:syncrow_web/pages/routines/models/ac/ac_operational_value.dart';
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
import 'package:syncrow_web/utils/constants/app_enum.dart';
import 'package:syncrow_web/utils/constants/assets.dart';

abstract class ACFunction extends DeviceFunction<AcStatusModel> {
  final String type;

  ACFunction({
    required super.deviceId,
    required super.deviceName,
    required super.code,
    required super.operationName,
    required super.icon,
    required this.type,
    super.step,
    super.unit,
    super.max,
    super.min,
  });

  List<ACOperationalValue> getOperationalValues();
}

class SwitchFunction extends ACFunction {
  SwitchFunction(
      {required super.deviceId, required super.deviceName, required type})
      : super(
          code: 'switch',
          operationName: 'Power',
          icon: Assets.assetsAcPower,
          type: type,
        );

  @override
  List<ACOperationalValue> getOperationalValues() => [
        ACOperationalValue(
          icon: Assets.assetsAcPower,
          description: "ON",
          value: true,
        ),
        ACOperationalValue(
          icon: Assets.assetsAcPowerOFF,
          description: "OFF",
          value: false,
        ),
      ];
}

class ModeFunction extends ACFunction {
  ModeFunction(
      {required super.deviceId, required super.deviceName, required type})
      : super(
          code: 'mode',
          operationName: 'Mode',
          icon: Assets.assetsFreezing,
          type: type,
        );

  @override
  List<ACOperationalValue> getOperationalValues() => [
        ACOperationalValue(
          icon: Assets.assetsAcCooling,
          description: "Cooling",
          value: TempModes.cold.name,
        ),
        ACOperationalValue(
          icon: Assets.assetsAcHeating,
          description: "Heating",
          value: TempModes.hot.name,
        ),
        ACOperationalValue(
          icon: Assets.assetsFanSpeed,
          description: "Ventilation",
          value: TempModes.wind.name,
        ),
      ];
}

class TempSetFunction extends ACFunction {
  TempSetFunction({
    required super.deviceId,
    required super.deviceName,
    required super.type,
  }) : super(
          code: 'temp_set',
          operationName: 'Set Temperature',
          icon: Assets.assetsTempreture,
          min: 200,
          max: 300,
          step: 1,
          unit: "°C",
        );

  @override
  List<ACOperationalValue> getOperationalValues() {
    List<ACOperationalValue> values = [];
    for (int temp = min!.toInt(); temp <= max!; temp += step!.toInt()) {
      values.add(ACOperationalValue(
        icon: Assets.assetsTempreture,
        description: "${temp / 10}°C",
        value: temp,
      ));
    }
    return values;
  }
}
class LevelFunction extends ACFunction {
  LevelFunction(
      {required super.deviceId, required super.deviceName, required type})
      : super(
          type: type,
          code: 'level',
          operationName: 'Fan Speed',
          icon: Assets.assetsFanSpeed,
        );

  @override
  List<ACOperationalValue> getOperationalValues() => [
        ACOperationalValue(
          icon: Assets.assetsAcFanLow,
          description: "LOW",
          value: FanSpeeds.low.name,
        ),
        ACOperationalValue(
          icon: Assets.assetsAcFanMiddle,
          description: "MIDDLE",
          value: FanSpeeds.middle.name,
        ),
        ACOperationalValue(
          icon: Assets.assetsAcFanHigh,
          description: "HIGH",
          value: FanSpeeds.high.name,
        ),
        ACOperationalValue(
          icon: Assets.assetsAcFanAuto,
          description: "AUTO",
          value: FanSpeeds.auto.name,
        ),
      ];
}

class ChildLockFunction extends ACFunction {
  ChildLockFunction(
      {required super.deviceId, required super.deviceName, required type})
      : super(
          type: type,
          code: 'child_lock',
          operationName: 'Child Lock',
          icon: Assets.assetsChildLock,
        );

  @override
  List<ACOperationalValue> getOperationalValues() => [
        ACOperationalValue(
          icon: Assets.assetsSceneChildLock,
          description: "Lock",
          value: true,
        ),
        ACOperationalValue(
          icon: Assets.assetsSceneChildUnlock,
          description: "Unlock",
          value: false,
        ),
      ];
}

class CurrentTempFunction extends ACFunction {
  final double min;
  final double max;
  final double step;
  final String unit = "°C";

  CurrentTempFunction(
      {required super.deviceId, required super.deviceName, required type})
      : min = -100,
        max = 990,
        step = 1,
        super(
          type: type,
          code: 'temp_current',
          operationName: 'Current Temperature',
          icon: Assets.currentTemp,
        );

  @override
  List<ACOperationalValue> getOperationalValues() {
    List<ACOperationalValue> values = [];
    for (int temp = min.toInt(); temp <= max; temp += step.toInt()) {
      values.add(ACOperationalValue(
        icon: Assets.currentTemp,
        description: "${temp / 10}°C",
        value: temp,
      ));
    }
    return values;
  }
}
