import '../models/bo/ac_bo.dart';
import '../repositories/ac_repository.dart';

class AcService {
  final AcRepository _repository;

  AcService({required AcRepository repository}) : _repository = repository;

  /// 获取空调状态
  Future<AcStatusBO> getStatus({required int deviceId}) async {
    final result = await _repository.getStatus(deviceId: deviceId);
    if (result.success && result.data != null) {
      return result.data!;
    }
    throw Exception(result.msg);
  }

  /// 空调控制操作
  Future<void> control({
    required int deviceId,
    bool? powerOn,
    int? targetTemperature,
    String? mode,
    String? fanSpeed,
  }) async {
    final result = await _repository.control(
      deviceId: deviceId,
      powerOn: powerOn,
      targetTemperature: targetTemperature,
      mode: mode,
      fanSpeed: fanSpeed,
    );
    if (!result.success) {
      throw Exception(result.msg);
    }
  }
}
