import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
import 'package:syncrow_web/pages/routines/models/ceiling_presence_sensor_functions.dart';
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/ceiling_sensor_dialog.dart';

abstract final class CeilingSensorHelper {
  const CeilingSensorHelper._();

  static Future<Map<String, dynamic>?> showCeilingSensorDialog({
    required BuildContext context,
    required String? uniqueCustomId,
    required List<DeviceFunction> functions,
    required List<DeviceFunctionData> deviceSelectedFunctions,
    required AllDevicesModel? device,
    required String dialogType,
  }) {
    return showDialog(
      context: context,
      builder: (context) => BlocProvider(
        create: (context) => FunctionBloc()
          ..add(
            InitializeFunctions(deviceSelectedFunctions),
          ),
        child: CeilingSensorDialog(
          uniqueCustomId: uniqueCustomId,
          functions: functions,
          deviceSelectedFunctions: deviceSelectedFunctions,
          device: device,
          dialogType: dialogType,
        ),
      ),
    );
  }

  static List<DeviceFunction<CpsOperationalValue>> getCeilingSensorFunctions({
    required String uuid,
    required String name,
  }) {
    return [
      CpsRadarSwitchFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsSpatialParameterSwitchFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsSensitivityFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsMovingSpeedFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'IF',
      ),
      CpsSpatialStaticValueFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'IF',
      ),
      CpsSpatialMotionValueFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'IF',
      ),
      CpsMaxDistanceOfDetectionFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsMaxDistanceOfStaticDetectionFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsDetectionRangeFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'IF',
      ),
      CpsDistanceOfMovingObjectsFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'IF',
      ),
      CpsPresenceJudgementThrsholdFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsMotionAmplitudeTriggerThresholdFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsPerpetualBoundaryFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsMotionTriggerBoundaryFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsMotionTriggerTimeFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsMotionToStaticTimeFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsEnteringNoBodyStateTimeFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsSelfTestResultFunctions(
        deviceName: name,
        deviceId: uuid,
        type: 'IF',
      ),
      CpsNobodyTimeFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsMovementFunctions(
        deviceName: name,
        deviceId: uuid,
        type: 'IF',
      ),
      CpsCustomModeFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsSpaceTypeFunctions(
        deviceName: name,
        deviceId: uuid,
        type: 'BOTH',
      ),
      CpsPresenceStatusFunctions(
        deviceName: name,
        deviceId: uuid,
        type: 'IF',
      ),
      CpsSportsParaFunction(
        deviceName: name,
        deviceId: uuid,
        type: 'IF',
      ),
    ];
  }

  static const toggleCodes = <String>{
    'radar_switch',
    'space_para_switch',
    'checking_result',
    'nobody_time',
    'body_movement',
    'custom_mode',
    'scene',
    'presence_state',
  };
}
