import 'package:dio/dio.dart';

Dio buildDioClient({
  required String baseUrl,
  required String origin,
  // required String apiKey,
  bool log = false,
}) {
  final dio = Dio(
    BaseOptions(
      baseUrl: baseUrl,
      connectTimeout: const Duration(seconds: 20),
      receiveTimeout: const Duration(seconds: 20),
      sendTimeout: const Duration(seconds: 20),
      headers: {
        // if (apiKey.isNotEmpty) 'x-api-key': apiKey,
        'accept': 'application/json',
        'content-type': 'application/json',
        'origin': origin,
      },
    ),
  );

  if (log) {
    dio.interceptors.add(
      LogInterceptor(
        request: true,
        requestHeader: false,
        requestBody: true,
        responseHeader: false,
        responseBody: true,
        error: true,
      ),
    );
  }

  return dio;
}
