import 'package:dio/dio.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

import 'package:superport_v2/core/network/api_client.dart';
import 'package:superport_v2/features/masters/warehouse/data/repositories/warehouse_repository_remote.dart';

class _MockApiClient extends Mock implements ApiClient {}

void main() {
  late ApiClient apiClient;
  late WarehouseRepositoryRemote repository;

  setUpAll(() {
    registerFallbackValue(Options());
    registerFallbackValue(CancelToken());
  });

  setUp(() {
    apiClient = _MockApiClient();
    repository = WarehouseRepositoryRemote(apiClient: apiClient);
  });

  test('include=zipcode 파라미터를 기본으로 전달한다', () async {
    when(
      () => apiClient.get<Map<String, dynamic>>(
        any(),
        query: any(named: 'query'),
        options: any(named: 'options'),
        cancelToken: any(named: 'cancelToken'),
      ),
    ).thenAnswer(
      (_) async => Response<Map<String, dynamic>>(
        data: {
          'items': [
            {'id': 1, 'warehouse_code': 'WH-001', 'warehouse_name': '1센터'},
          ],
        },
        requestOptions: RequestOptions(path: '/api/v1/warehouses'),
        statusCode: 200,
      ),
    );

    await repository.list();

    final captured = verify(
      () => apiClient.get<Map<String, dynamic>>(
        captureAny(),
        query: captureAny(named: 'query'),
        options: any(named: 'options'),
        cancelToken: any(named: 'cancelToken'),
      ),
    ).captured;
    final path = captured[0] as String;
    final query = captured[1] as Map<String, dynamic>;

    expect(path, equals('/api/v1/warehouses'));
    expect(query['include'], 'zipcode');
  });
}
