import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

import 'package:http/http.dart' as http;
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';

import 'package:fotodocumentation/controller/customer_controller.dart';
import 'package:fotodocumentation/controller/login_controller.dart';
import 'package:fotodocumentation/controller/picture_controller.dart';
import 'package:fotodocumentation/l10n/app_localizations.dart';
import 'package:fotodocumentation/utils/login_credentials.dart';
import 'package:fotodocumentation/utils/jwt_token_storage.dart';
import 'package:fotodocumentation/utils/global_router.dart';

import 'test_utils.mocks.dart';

void setScreenSize(WidgetTester tester, int width, int height) {
  final dpi = tester.view.devicePixelRatio;
  tester.view.physicalSize = Size(width * dpi, height * dpi);
}

MockLoginCredentials getDefaultLoginCredentials() {
  var mockLoginCredentials = MockLoginCredentials();
  when(mockLoginCredentials.isLoggedIn).thenReturn(true);
  return mockLoginCredentials;
}

Future<void> pumpApp(WidgetTester tester, Widget widget) async {
  await tester.pumpWidget(MaterialApp(
      title: 'App',
      localizationsDelegates: [
        AppLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        Locale('de'),
      ],
      home: Scaffold(body: widget)));
  await tester.pump();
}

Future<void> pumpAppConfig(WidgetTester tester, String initialLocation) async {
  await tester.pumpWidget(MaterialApp.router(
      title: 'App',
      localizationsDelegates: [
        AppLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        Locale('de'),
      ],
      routerConfig: GlobalRouter.createRouter(initialLocation)));
  await tester.pump();
}

// dart run build_runner build
@GenerateMocks([
  LoginCredentials,
  LoginController,
  CustomerController,
  PictureController,
  JwtTokenStorage,
  http.Client,
])
void main() {}
