import 'package:dio/dio.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:recording_tool/app/config/api_common.dart';
import 'package:recording_tool/core/network/api_client.dart';
import 'package:recording_tool/core/network/http_method.dart';
import 'package:recording_tool/core/network/providers/dio_providers.dart';
import 'package:recording_tool/features/events/model/model_event_info.dart';
import 'package:recording_tool/features/events/request_model/request_model_event.dart';

final eventsServerProvider = Provider<EventsServer>((ref) {
  return EventsServer(ref.watch(apiClientProvider));
});

class EventsServer {
  const EventsServer(this._apiClient);

  final ApiClient _apiClient;

  Future<EventRegistrationList> fetchPlayerRegistrationList(
    PlayerRegistrationListReq req,
  ) {
    return _apiClient.request<EventRegistrationList>(
      AuthApi.playerRegistrationList.path,
      method: HttpMethod.get,
      data: FormData.fromMap(req.toFormDataMap()),
      parser: EventRegistrationList.fromJson,
    );
  }

  Future<StreamKeyResponse> fetchStreamKey(StreamKeyReq req) {
    return _apiClient.request<StreamKeyResponse>(
      AuthApi.getStreamKey.path,
      method: HttpMethod.get,
      data: FormData.fromMap(req.toFormDataMap()),
      parser: StreamKeyResponse.fromJson,
    );
  }

  /// 人工设置晋级/淘汰
  Future<void> setTeamStatus({required SetTeamStatusReq req}) {
    print('req: ${req.toJson()}');
    return _apiClient.post(
      AuthApi.setTeamStatus.path,
      data: req.toJson(),
      parser: (json) => json,
    );
  }
}
