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/core/application/clients/api/api_exception.dart';
import 'package:krow/features/clock_manual/data/clock_manual_gql.dart';

@singleton
class ClockManualApiProvider {
  final ApiClient _client;

  ClockManualApiProvider({required ApiClient client}) : _client = client;

  Future<void> trackClientClockin(String positionStaffId) async {
    final QueryResult result = await _client.mutate(
      schema: trackClientClockinMutation,
      body: {'position_staff_id': positionStaffId},
    );
    if (result.hasException) {
      throw parseBackendError(result.exception!);
    }
  }

  Future<void> trackClientClockout(String positionStaffId) async {
    final QueryResult result = await _client.mutate(
      schema: trackClientClockoutMutation,
      body: {'position_staff_id': positionStaffId},
    );
    if (result.hasException) {
      throw parseBackendError(result.exception!);
    }
  }

  Future<void> cancelClockin(String positionStaffId) async {
    final QueryResult result = await _client.mutate(
      schema: cancelClockinMutation,
      body: {'position_staff_id': positionStaffId},
    );
    if (result.hasException) {
      throw parseBackendError(result.exception!);
    }
  }
}
