import 'dart:io';

import 'package:cinema/common/env_module.dart';
import 'package:cinema/feature/version/version.dart';
import 'package:dio/dio.dart';
import 'package:injectable/injectable.dart';

const dioAPI = 'api';
const dioIMAGES = 'images';

@module
abstract class DioModule {
  @Named(dioAPI)
  @lazySingleton
  Dio apiDio(@Named(apiKey) String apiKey) => Dio(
    BaseOptions(
      baseUrl: 'https://api.themoviedb.org/3',
      connectTimeout: const Duration(seconds: 10),
      receiveTimeout: const Duration(seconds: 10),
      headers: {
        'Authorization': 'Bearer $apiKey',
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'User-Agent': 'Cinema Service (v${Version().appVersion})',
      },
    ),
  );

  @Named(dioIMAGES)
  @lazySingleton
  Dio get imagesDio => Dio(
    BaseOptions(
      baseUrl: 'https://image.tmdb.org/t/p/original',
      connectTimeout: const Duration(seconds: 10),
      receiveTimeout: const Duration(seconds: 10),
    ),
  );
}
