import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';
import '../../../data/models/warehouse/warehouse_dto.dart';
import '../../repositories/warehouse_location_repository.dart';
import '../../../core/errors/failures.dart';
import '../base_usecase.dart';

/// 창고 위치 상세 조회 UseCase
@injectable
class GetWarehouseLocationDetailUseCase implements UseCase<WarehouseLocationDto, int> {
  final WarehouseLocationRepository repository;

  GetWarehouseLocationDetailUseCase(this.repository);

  @override
  Future<Either<Failure, WarehouseLocationDto>> call(int id) async {
    try {
      final result = await repository.getWarehouseLocationById(id);
      return result.map((location) => WarehouseLocationDto(
        id: location.id ?? 0,
        name: location.name,
        address: location.address.toString(),
        isActive: true, // Default value since model doesn't have isActive
        createdAt: DateTime.now(), // Add required createdAt parameter
      ));
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }
}