import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/domain/entities/restaurant.dart';
import 'package:lunchpick/presentation/pages/restaurant_list/widgets/restaurant_card.dart';
import 'package:lunchpick/presentation/providers/visit_provider.dart';

void main() {
  Restaurant buildRestaurant({required bool needsAddressVerification}) {
    return Restaurant(
      id: '1',
      name: '테스트 식당',
      category: '한식',
      subCategory: '찌개',
      roadAddress: '서울시 중구',
      jibunAddress: '서울시 중구',
      latitude: 37.5665,
      longitude: 126.9780,
      source: DataSource.USER_INPUT,
      createdAt: DateTime(2024, 1, 1),
      updatedAt: DateTime(2024, 1, 1),
      needsAddressVerification: needsAddressVerification,
    );
  }

  ProviderScope wrapWithProviders(Widget child) {
    return ProviderScope(
      overrides: [
        lastVisitDateProvider.overrideWithProvider(
          (id) => FutureProvider((ref) async => null),
        ),
      ],
      child: MaterialApp(home: child),
    );
  }

  testWidgets('주소 확인 배지가 표시되고 거리 뱃지가 노출된다', (tester) async {
    final restaurant = buildRestaurant(needsAddressVerification: true);

    await tester.pumpWidget(
      wrapWithProviders(
        RestaurantCard(restaurant: restaurant, distanceKm: 2.3),
      ),
    );

    await tester.pumpAndSettle();

    expect(find.text('주소확인'), findsOneWidget);
    expect(find.text('2.0km 이상'), findsOneWidget);
  });

  testWidgets('주소 확인 플래그가 없으면 배지가 숨겨진다', (tester) async {
    final restaurant = buildRestaurant(needsAddressVerification: false);

    await tester.pumpWidget(
      wrapWithProviders(
        RestaurantCard(restaurant: restaurant, distanceKm: null),
      ),
    );

    await tester.pumpAndSettle();

    expect(find.text('주소확인'), findsNothing);
  });
}
