import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:pretty_dio_logger/pretty_dio_logger.dart';

class AdiveryService {
  final String appId = 'ecc70180-4f9e-4ee9-b017-87cc5d34f0b2';
  final String placementId = 'd67314c0-7fe8-4fd1-b409-7088cfb50485';
  final String placementIdTest = 'd3d19c2a-142c-4551-92f1-1d2c38aea3ec';
  static const _canLog = kDebugMode && !kIsWeb;

  static final Dio _dio = Dio(BaseOptions(
    baseUrl: 'https://fetch.adivery.com/api/v1',
    connectTimeout: const Duration(minutes: 1),
    responseType: ResponseType.json,
  ))
    ..interceptors.add(PrettyDioLogger(enabled: _canLog));

  void initialize(BuildContext context) async {
    await _dio.post('/installation', data: {
      "device": {
        "os": "Android",
        "screen_dpi": 0,
        "screen_width": MediaQuery.of(context).size.width.round(),
        "screen_height": MediaQuery.of(context).size.height.round(),
        "api_level": 16
      },
      "package": 'com.adivery.flutter',
      "version_code": 1,
      "app_id": appId,
      "update_time": 0,
      "install_time": 0,
    });
  }
}
