import '../utils/http/response_model.dart';
import '../utils/http/dio_request.dart';
import '../models/bo/ac_bo.dart';

class AcRepository {
  /// 获取空调状态
  /// GET /app/device/ac/status
  Future<ResponseModel<AcStatusBO>> getStatus({required int deviceId}) {
    return DioRequest.instance.get<AcStatusBO>(
      '/app/device/ac/status',
      queryParameters: {'deviceId': deviceId},
      fromJsonT: (data) =>
          AcStatusBO.fromJson(data as Map<String, dynamic>),
    );
  }

  /// 空调控制操作
  /// POST /app/device/ac/control
  Future<ResponseModel<Map<String, dynamic>>> control({
    required int deviceId,
    bool? powerOn,
    int? targetTemperature,
    String? mode,
    String? fanSpeed,
  }) {
    final params = <String, dynamic>{
      'deviceId': deviceId,
    };
    if (powerOn != null) params['powerOn'] = powerOn;
    if (targetTemperature != null) params['targetTemperature'] = targetTemperature;
    if (mode != null) params['mode'] = mode;
    if (fanSpeed != null) params['fanSpeed'] = fanSpeed;

    return DioRequest.instance.post<Map<String, dynamic>>(
      '/app/device/ac/control',
      data: params,
    );
  }
}
