import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';
import '../../../data/models/warehouse/warehouse_location_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,
        name: location.name,
        zipcodesZipcode: location.address, // Map address to zipcode
        remark: location.remark,
        registeredAt: DateTime.now(),
      ));
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }
}