import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:injectable/injectable.dart';
import 'package:krow/core/application/clients/api/api_client.dart';
import 'package:krow/features/rate_staff/data/gql.dart';

@singleton
class ClientProfileApiProvider {
  ClientProfileApiProvider(this._client);

  final ApiClient _client;

  Future<void> updateStaffRating(
      {required String positionId,
      required int rating,
      String? reason,
      String? details,
      bool? isBlocked ,
      bool? isFavorite }) async {
    final QueryResult result = await _client.mutate(
      schema: updateStaffRatingMutationSchema,
      body: {
        'input': {
          'position_staff_id': positionId,
          'rating': rating,
          if (reason != null && reason.isNotEmpty) 'reason': reason,
          if (details != null && details.isNotEmpty) 'details': details.trim(),
          'is_blocked': isBlocked??false,
          'is_favorite': isFavorite??false,
        },
      },
    );

    if (result.hasException) {
      throw Exception(result.exception.toString());
    }
  }
}
