import 'package:dio/dio.dart';
import 'package:superport_v2/core/common/models/paginated_result.dart';
import 'package:superport_v2/core/network/api_client.dart';
import 'package:superport_v2/core/network/api_routes.dart';

import '../../domain/entities/uom.dart';
import '../../domain/repositories/uom_repository.dart';
import '../dtos/uom_dto.dart';

/// 단위(UOM) 마스터 API를 호출하는 원격 저장소.
class UomRepositoryRemote implements UomRepository {
  UomRepositoryRemote({required ApiClient apiClient}) : _api = apiClient;

  final ApiClient _api;

  static const _basePath = '${ApiRoutes.apiV1}/uoms';

  /// UOM 목록을 조회한다.
  @override
  Future<PaginatedResult<Uom>> list({
    int page = 1,
    int pageSize = 50,
    String? query,
    bool? isActive,
  }) async {
    final response = await _api.get<Map<String, dynamic>>(
      _basePath,
      query: {
        'page': page,
        'page_size': pageSize,
        if (query != null && query.isNotEmpty) 'q': query,
        if (isActive != null) 'active': isActive,
      },
      options: Options(responseType: ResponseType.json),
    );
    return UomDto.parsePaginated(response.data ?? const {});
  }
}
