import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'src/app.dart';
import 'src/shared/data/local/app_database.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  try {
    await dotenv.load(fileName: '.env');
    log('Environment loaded: ${dotenv.env['ENVIRONMENT']}');
    log('API URL: ${dotenv.env['API_BASE_URL']}');
  } catch (e) {
    log('Could not load .env file: $e');
    log('Using default production values');
  }

  await SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);

  final database = AppDatabase();

  runApp(
    ProviderScope(
      overrides: [appDatabaseProvider.overrideWithValue(database)],
      child: const SLRPGApp(),
    ),
  );
}

final appDatabaseProvider =
    Provider<AppDatabase>((ref) => throw UnimplementedError());
