import 'package:dartz/dartz.dart';
import '../../repositories/equipment_repository.dart';
import '../../../data/models/equipment/equipment_dto.dart';
import '../../../core/errors/failures.dart';
import '../base_usecase.dart';

/// 장비 시리얼 검색 UseCase
class GetEquipmentBySerialUseCase extends UseCase<EquipmentDto, String> {
  final EquipmentRepository _equipmentRepository;

  GetEquipmentBySerialUseCase(this._equipmentRepository);

  @override
  Future<Either<Failure, EquipmentDto>> call(String serial) async {
    if (serial.trim().isEmpty) {
      return Left(ValidationFailure(message: '시리얼 번호를 입력해주세요.'));
    }
    
    return await _equipmentRepository.getEquipmentBySerial(serial);
  }
}

/// 장비 바코드 검색 UseCase
class GetEquipmentByBarcodeUseCase extends UseCase<EquipmentDto, String> {
  final EquipmentRepository _equipmentRepository;

  GetEquipmentByBarcodeUseCase(this._equipmentRepository);

  @override
  Future<Either<Failure, EquipmentDto>> call(String barcode) async {
    if (barcode.trim().isEmpty) {
      return Left(ValidationFailure(message: '바코드를 입력해주세요.'));
    }
    
    return await _equipmentRepository.getEquipmentByBarcode(barcode);
  }
}

/// 회사별 장비 조회 UseCase
class GetEquipmentsByCompanyUseCase extends UseCase<List<EquipmentDto>, int> {
  final EquipmentRepository _equipmentRepository;

  GetEquipmentsByCompanyUseCase(this._equipmentRepository);

  @override
  Future<Either<Failure, List<EquipmentDto>>> call(int companyId) async {
    if (companyId <= 0) {
      return Left(ValidationFailure(message: '올바른 회사 ID를 입력해주세요.'));
    }
    
    return await _equipmentRepository.getEquipmentsByCompany(companyId);
  }
}