import 'package:absensi_sas/model/logout_response_model.dart';
import 'package:google_sign_in/google_sign_in.dart';

import '../model/auth_model.dart';
import 'base_repository.dart';

class AuthRepository extends BaseRepository {
  AuthRepository({required super.graphql, required super.dio});

  // login
  Future<AuthModel> login(
    String email,
    String idGoogleSignIn,
  ) async {
    const String query =
        r'''mutation($emailParam:String!, $id_google_sign_in_Param:String!){ loginAttendance(email:$emailParam, id_google_sign_in:$id_google_sign_in_Param){ staff_id nip name email phone_number token id_google_sign_in company_id company_name } }''';

    Map<String, dynamic> inpVariables = {
      "emailParam": email,
      "id_google_sign_in_Param": idGoogleSignIn
    };
    final resp = await postGraphQlMutation(query, inpVariables);
    // final loginData = AuthModel.fromJson(resp['userLogin']);

    print('obj loginAttendance : ${resp["loginAttendance"]}');
    print('token : ${resp["loginAttendance"]["token"]}');

    final result = AuthModel(
      token: resp["loginAttendance"]["token"],
      model: StaffModel.fromJson(resp["loginAttendance"]),
    );
    return result;
  }

  // logout
  Future<LogoutResponseModel> logout(
      String email, String idGoogleSignIn) async {
    const String query =
        r'''mutation($emailParam:String!, $id_google_sign_in_Param:String!){ logoutAttendance(email:$emailParam, id_google_sign_in:$id_google_sign_in_Param){ staff_id nip name email phone_number token id_google_sign_in company_id company_name } }''';

    Map<String, dynamic> inpVariables = {
      "emailParam": email,
      "id_google_sign_in_Param": idGoogleSignIn
    };
    final resp = await postGraphQlMutation(query, inpVariables);
    // final loginData = AuthModel.fromJson(resp['userLogin']);

    // final result = resp['logoutAttendance']['status'];

    final result = LogoutResponseModel(
        message: resp['logoutAttendance']['message'],
        status: resp['logoutAttendance']['status']);
    return result;
  }
}
