import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'app.dart';
import 'player/audio_handler.dart';
import 'player/player_provider.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final handler = await AudioService.init(
    builder: () => MinstrelAudioHandler(),
    config: const AudioServiceConfig(
      androidNotificationChannelId: 'com.fabledsword.minstrel.audio',
      androidNotificationChannelName: 'Minstrel playback',
      androidNotificationOngoing: true,
      // 8a: hand external surfaces (notification / lock screen / Wear)
      // a downscaled cover instead of full-res album art — smaller
      // payload, faster paint, lower memory. 300px is ample for those
      // targets. preloadArtwork warms it so the first paint isn't blank.
      artDownscaleWidth: 300,
      artDownscaleHeight: 300,
      preloadArtwork: true,
    ),
  );
  runApp(ProviderScope(
    overrides: [audioHandlerProvider.overrideWithValue(handler)],
    child: const MinstrelApp(),
  ));
}
