import '../models/bo/device_control_bo.dart';
import '../repositories/device_control_repository.dart';

class DeviceControlService {
  final DeviceControlRepository _repository;

  DeviceControlService({required DeviceControlRepository repository})
      : _repository = repository;

  Future<DeviceControlBO> getDetail({required int deviceId}) async {
    final result = await _repository.getDetail(deviceId: deviceId);
    if (result.success && result.data != null) {
      return result.data!;
    }
    throw Exception(result.msg);
  }

  Future<void> powerOn({required int deviceId}) async {
    final result = await _repository.powerOn(deviceId: deviceId);
    if (!result.success) {
      throw Exception(result.msg);
    }
  }

  Future<void> powerOff({required int deviceId}) async {
    final result = await _repository.powerOff(deviceId: deviceId);
    if (!result.success) {
      throw Exception(result.msg);
    }
  }
}