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/providers/dio_providers.dart';
import 'package:recording_tool/features/competition_teams/model/model_competition_team.dart';
import 'package:recording_tool/features/competition_teams/model/model_competition_team_detail.dart';

final competitionTeamsServerProvider = Provider<CompetitionTeamsServer>((ref) {
  return CompetitionTeamsServer(ref.watch(apiClientProvider));
});

class CompetitionTeamsServer {
  CompetitionTeamsServer(this._apiClient);

  final ApiClient _apiClient;

  Future<CompetitionTeamPageResult> fetchPage({
    required int page,
    required int pageSize,
  }) {
    return _apiClient.get(
      AuthApi.getTeamList.path,
      queryParameters: {'page': page, 'pageSize': pageSize},
      parser: (json) => CompetitionTeamPageResult.fromJson(
        json,
        page: page,
        pageSize: pageSize,
      ),
    );
  }

  Future<CompetitionTeamDetail> fetchTeamDetail({
    required String itemId,
    required String eventId,
    String? scheduleId,
    String? opponentId,
  }) {
    return _apiClient.post(
      AuthApi.getTeamDetail.path,
      data: {
        'itemId': itemId,
        'eventId': eventId,
        'scheduleId': scheduleId,
        'opponentId': opponentId,
      },
      parser: (json) => CompetitionTeamDetail.fromResponse(json),
    );
  }
}
