import { Device } from '../../../domain/entities/device';
import { NotFoundError } from '../../../domain/errors/not-found-error';
import { IDeviceRepository } from '../../../domain/repositories/device-repository';
import { UpdateDeviceStatusInput } from '../../dto/device.dto';

export class UpdateDeviceStatusUseCase {
  constructor(private readonly deviceRepository: IDeviceRepository) {}

  async execute(id: string, input: UpdateDeviceStatusInput): Promise<Device> {
    const device = await this.deviceRepository.findById(id);
    if (!device) {
      throw new NotFoundError('Device', id);
    }

    const updated = device.updateStatus(input.status);
    return this.deviceRepository.update(updated);
  }
}
