import 'dart:async';
import 'dart:convert';
import 'dart:developer';

import 'package:flutter/foundation.dart';
import 'package:hub/features/notification/index.dart';
import 'package:hub/features/storage/index.dart';

import 'package:hub/shared/utils/log_util.dart';
import 'package:hub/shared/utils/validator_util.dart';

import '/flutter_flow/flutter_flow_util.dart';
import 'api_manager.dart';

export 'api_manager.dart' show ApiCallResponse;

const _kPrivateApiFunctionName = 'ffPrivateApiCall';

/// Start PHP Group Code

abstract class Api {
  GetLicense getLicense = GetLicense();
}

class PhpGroup extends Api {
  static String getBaseUrl() => 'https://freaccess.com.br/freaccess';
  static Map<String, String> headers = {};
  static LoginCall loginCall = LoginCall();
  static UpdToken updToken = UpdToken();
  static RegisterCall registerCall = RegisterCall();
  static ForgotPasswordCall forgotPasswordCall = ForgotPasswordCall();
  static ChangePasswordCall changePasswordCall = ChangePasswordCall();
  static GetLocalsCall getLocalsCall = GetLocalsCall();
  static PostScheduleVisitorCall postScheduleVisitorCall =
      PostScheduleVisitorCall();
  static PostScheduleVisitCall postScheduleVisitCall = PostScheduleVisitCall();
  static GetScheduleVisitCall getScheduleVisitCall = GetScheduleVisitCall();
  static GetDadosCall getDadosCall = GetDadosCall();
  static GetVisitorByDocCall getVisitorByDocCall = GetVisitorByDocCall();
  static GetFotoVisitanteCall getFotoVisitanteCall = GetFotoVisitanteCall();
  static PostProvVisitSchedulingCall postProvVisitSchedulingCall =
      PostProvVisitSchedulingCall();
  static GetVisitsCall getVisitsCall = GetVisitsCall();
  static DeleteVisitCall deleteVisitCall = DeleteVisitCall();
  static GetPessoasLocalCall getPessoasLocalCall = GetPessoasLocalCall();
  static RespondeSolicitacaoCall respondeSolicitacaoCall =
      RespondeSolicitacaoCall();
  static GetAccessCall getAccessCall = GetAccessCall();
  static GetLiberationsCall getLiberationsCall = GetLiberationsCall();
  static GetMessagesCall getMessagesCall = GetMessagesCall();
  static ChangeNotifica changeNotifica = ChangeNotifica();
  static UpdateIDE updateIDE = UpdateIDE();
  static RespondeVinculo resopndeVinculo = RespondeVinculo();
  static ChangePass changePass = ChangePass();
  static ChangePanic changePanic = ChangePanic();
  static DeleteAccount deleteAccount = DeleteAccount();
  static CancelaVisita cancelaVisita = CancelaVisita();
  static BuscaEnconcomendas buscaEnconcomendas = BuscaEnconcomendas();
  static RegisterPet registerPet = RegisterPet();
  static DeletePet deletePet = DeletePet();
  static UpdatePet updatePet = UpdatePet();
  static GetPets getPets = GetPets();
  static GetPetPhoto getPetPhoto = GetPetPhoto();
  static UnregisterDevice unregisterDevice = UnregisterDevice();
  static GetVehiclesByProperty getVehiclesByProperty = GetVehiclesByProperty();
  static GetResidentsByProperty getResidentsByProperty =
      GetResidentsByProperty();
  static GetOpenedVisits getOpenedVisits = GetOpenedVisits();
  GetLicense getLicense = GetLicense();
  static GetProvSchedules getProvSchedules = GetProvSchedules();
}

class GetProvSchedules {
  Future<ApiCallResponse> call(final String page, final String status) async {
    final String baseUrl = PhpGroup.getBaseUrl();
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getAgendamentoProv';
    const String pageSize = '10';
    final bool isFiltered = status != '' && status != '.*';
    // const String baseUrl = 'http://localhost:3000';
    return await ApiManager.instance.makeApiCall(
      callName: 'getProvSchedules',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      params: {
        if (isFiltered) 'status': status,
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'page': page,
        'pageSize': pageSize,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class GetOpenedVisits {
  Future<ApiCallResponse> call(final String page) async {
    final String baseUrl = PhpGroup.getBaseUrl();
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getOpenedVisits';
    const String pageSize = '10';
    return await ApiManager.instance.makeApiCall(
      callName: 'getOpenedVisits',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'page': page,
        'pageSize': pageSize,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class GetResidentsByProperty {
  Future<ApiCallResponse> call(final String page) async {
    final String baseUrl = PhpGroup.getBaseUrl();
    final String devUUID =
        await StorageHelper().get(ProfileStorageKey.devUUID.key) ?? '';
    final String userUUID =
        await StorageHelper().get(ProfileStorageKey.userUUID.key) ?? '';
    final String cliID =
        await StorageHelper().get(ProfileStorageKey.clientUUID.key) ?? '';
    const String atividade = 'getResidentsByProperty';
    const String pageSize = '10';
    return await ApiManager.instance.makeApiCall(
      callName: 'getResidentsByProperty',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'page': page,
        'pageSize': pageSize,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      alwaysAllowBody: false,
    );
  }
}

class GetVehiclesByProperty {
  Future<ApiCallResponse> call(final String page) async {
    final String baseUrl = PhpGroup.getBaseUrl();
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getVehiclesByProperty';
    const String pageSize = '10';
    return await ApiManager.instance.makeApiCall(
      callName: 'getVehiclesByProperty',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'page': page,
        'pageSize': pageSize,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      alwaysAllowBody: false,
    );
  }

  static GetLicense getLicense = GetLicense();
}

class GetLicense {
  Future<ApiCallResponse> call() async {
    final String baseUrl = PhpGroup.getBaseUrl();
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';

    return await ApiManager.instance.makeApiCall(
      callName: 'getLicense',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': 'getLicenca',
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class UnregisterDevice {
  Future<ApiCallResponse> call() async {
    final String baseUrl = PhpGroup.getBaseUrl();
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';

    return await ApiManager.instance.makeApiCall(
      callName: 'unregisterDevice',
      apiUrl: '$baseUrl/unregisterDevice.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class DeletePet {
  Future<ApiCallResponse> call({final int? petID = 0}) async {
    final String baseUrl = PhpGroup.getBaseUrl();
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'excluirPet';

    return await ApiManager.instance.makeApiCall(
      callName: 'deletePet',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'petId': petID,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class UpdatePet {
  Future<ApiCallResponse> call({
    final int? petID,
    final String? image,
    final String? name,
    final String? species,
    final String? breed,
    final String? color,
    final String? birthdayDate,
    final String? gender,
    final String? size,
    final String? notes,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'atualizarPet';

    return await ApiManager.instance.makeApiCall(
      callName: 'updatePet',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'id': petID,
        'image': image,
        'name': name,
        'species': species,
        'breed': breed,
        if (color != '') 'color': color,
        if (birthdayDate != '')
          'birthdayDate':
              ValidatorUtil.toISO8601USA('dd/MM/yyyy', birthdayDate!),
        'gender': gender,
        'size': size,
        if (notes != '') 'notes': notes,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class GetPets {
  Future<ApiCallResponse> call({
    final int? page,
    final int? pageSize,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'consultaPets';

    return await ApiManager.instance.makeApiCall(
      callName: 'getPets',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'page': page,
        'pageSize': pageSize,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      alwaysAllowBody: false,
    );
  }
}

class GetPetPhoto {
  Future<ApiCallResponse> call({final int? petId}) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'consultaFotoPet';

    return await ApiManager.instance.makeApiCall(
      callName: 'getPetPhoto',
      apiUrl: '$baseUrl/getImage.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'atividade': atividade,
        'cliID': cliID,
        'petId': petId,
      },
      bodyType: BodyType.BLOB,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
    );
  }
}

class RegisterPet {
  Future<ApiCallResponse> call({
    final String? image,
    final String? name,
    final String? species,
    final String? breed,
    final String? color,
    final String? birthdayDate,
    final String? gender,
    final String? size,
    final String? notes,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'cadastrarPet';

    return await ApiManager.instance.makeApiCall(
      callName: 'registerPet',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'image': image,
        'name': name,
        'species': species,
        'breed': breed,
        if (color != '') 'color': color,
        if (birthdayDate != '')
          'birthdayDate':
              ValidatorUtil.toISO8601USA('dd/MM/yyyy', birthdayDate!),
        'gender': gender,
        'size': size,
        if (notes != '') 'notes': notes,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class BuscaEnconcomendas {
  Future<ApiCallResponse> call({
    final String? page,
    final String? pageSize,
    final String? adresseeType,
    final String? status,
  }) async {
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getEncomendas';

    final String baseUrl = PhpGroup.getBaseUrl();

    return await ApiManager.instance.makeApiCall(
      callName: 'getEncomendas',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'atividade': atividade,
        'cliID': cliID,
        'page': page,
        'pageSize': pageSize,
        'adresseeType': adresseeType,
        'status': status,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      alwaysAllowBody: false,
    );
  }
}

class CancelaVisita {
  Future<ApiCallResponse> call({
    final int? idDestino,
    final int? idVisita,
    final String? AccessKey,
    final String? UsuEmail,
    final String? DevDesc,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'cancelaVisita';

    return await ApiManager.instance.makeApiCall(
      callName: 'cancelaVisita',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'atividade': atividade,
        'cliID': cliID,
        'idVisita': idVisita,
        'AccessKey': AccessKey,
        'UsuEmail': UsuEmail,
        'DevDesc': DevDesc,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      alwaysAllowBody: false,
    );
  }
}

class DeleteAccount {
  Future<ApiCallResponse> call() async {
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';

    final String baseUrl = PhpGroup.getBaseUrl();
    return await ApiManager.instance.makeApiCall(
      callName: 'deleteAccount',
      apiUrl: '$baseUrl/deleteAccount.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class ChangePanic {
  Future<ApiCallResponse> call({
    final String? newSenhaPanico,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'updVisitado';

    return await ApiManager.instance.makeApiCall(
      callName: 'changePass',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'newSenhaPanico': newSenhaPanico,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class ChangePass {
  Future<ApiCallResponse> call({
    final String? newSenha,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'updVisitado';

    return await ApiManager.instance.makeApiCall(
      callName: 'changePass',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'newSenha': newSenha,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class RespondeVinculo {
  Future<ApiCallResponse> call({
    final String? tarefa,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';

    return await ApiManager.instance.makeApiCall(
      callName: 'respondeVinculo',
      apiUrl: '$baseUrl/responderVinculo.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'tarefa': tarefa,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class ChangeNotifica {
  Future<ApiCallResponse> call({
    final String? notifica,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'updVisitado';

    return await ApiManager.instance.makeApiCall(
      callName: 'changeNotifica',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'notifica': notifica,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class UpdateIDE {
  Future<ApiCallResponse> call() async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    final String newIde =
        (await StorageHelper().get(ProfileStorageKey.userDevUUID.key)) ?? '';
    const String atividade = 'updVisitado';

    return await ApiManager.instance.makeApiCall(
      callName: 'changeNotifica',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliUUID,
        'atividade': atividade,
        'newIde': newIde,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class UpdToken {
  Future<ApiCallResponse> call() async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String token =
        (await StorageHelper().get(SecureStorageKey.token.value)) ?? '';

    return await ApiManager.instance.makeApiCall(
      callName: 'updToken',
      apiUrl: '$baseUrl/updtoken.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'token': token,
        'devid': devUUID,
        'useruuid': userUUID,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      alwaysAllowBody: false,
    );
  }
}

class LoginCall {
  Future<ApiCallResponse> call() async {
    final String baseUrl = PhpGroup.getBaseUrl();
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String email =
        (await StorageHelper().get(SecureStorageKey.email.value)) ?? '';
    final String password =
        (await StorageHelper().get(SecureStorageKey.password.value)) ?? '';
    final String type =
        (await StorageHelper().get(SecureStorageKey.deviceType.value)) ?? '';
    final String description =
        (await StorageHelper().get(SecureStorageKey.deviceDescription.value)) ??
            '';
    late final String token;
    try {
      token = await FirebaseMessagingService.getToken();
      if (token == 'null' || token.isEmpty) throw Exception('Token is empty');
    } catch (e, s) {
      token = '';
      log('Error getting token', error: e, stackTrace: s);
      LogUtil.requestAPIFailed('login.php', email, "Login", e, s);
    }

    return await ApiManager.instance.makeApiCall(
      callName: 'login',
      apiUrl: '$baseUrl/login.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'email': email.toLowerCase(),
        'password': password,
        'uuid': devUUID,
        'token': token,
        'tipo': type,
        'descricao': description,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class RegisterCall {
  Future<ApiCallResponse> call({
    required final String name,
    required final String email,
    required final String password,
    required final String token,
    required final String uuid,
    required final String tipo,
    required final String descricao,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    return await ApiManager.instance.makeApiCall(
      callName: 'register',
      apiUrl: '$baseUrl/registro.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'name': name,
        'email': email.toLowerCase(),
        'password': password,
        'token': token,
        'uuid': uuid,
        'tipo': tipo,
        'descricao': descricao,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class ChangePasswordCall {
  Future<ApiCallResponse> call({
    required final String email,
    required final String token,
    required final String psswd,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();
    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';

    return await ApiManager.instance.makeApiCall(
      callName: 'changePassword',
      apiUrl: '$baseUrl/alterarSenha.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'email': email,
        'token': token,
        'senha': psswd,
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class ForgotPasswordCall {
  Future<ApiCallResponse> call({
    final String? email,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    return await ApiManager.instance.makeApiCall(
      callName: 'forgotPassword',
      apiUrl: '$baseUrl/iforgot.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'email': email,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class GetLocalsCall {
  Future<ApiCallResponse> call() async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        await StorageHelper().get(ProfileStorageKey.devUUID.key) ?? '';
    final String userUUID =
        await StorageHelper().get(ProfileStorageKey.userUUID.key) ?? '';

    return await ApiManager.instance
        .makeApiCall(
          callName: 'getLocals',
          apiUrl: '$baseUrl/getLocais.php',
          callType: ApiCallType.POST,
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
          },
          params: {
            'devUUID': devUUID,
            'userUUID': userUUID,
          },
          bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
          returnBody: true,
          encodeBodyUtf8: false,
          decodeUtf8: false,
          cache: false,
          isStreamingApi: false,
          alwaysAllowBody: false,
        )
        .timeout(const Duration(seconds: 30));
  }

  List? locais(dynamic response) => getJsonField(
        response,
        r'''$.locais''',
        true,
      ) as List?;
}

class PostScheduleVisitorCall {
  Future<ApiCallResponse> call({
    required final String documento,
    required final String nome,
    required final String tipo,
    required final String foto,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'putVisitante';

    return await ApiManager.instance.makeApiCall(
      callName: 'postScheduleVisitor',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'Documento': documento,
        'Nome': nome,
        'Tipo': tipo,
        'Foto': foto,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  String? errorMsg(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.error_msg''',
      ));
}

class PostScheduleVisitCall {
  Future<ApiCallResponse> call({
    final String? devDesc,
    final String? idVisitante,
    final String? dtInicio,
    final String? dtFim,
    final String? unica,
    final int? idMotivo,
    final int? idNAC,
    final String? obs,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'putVisita';

    return await ApiManager.instance.makeApiCall(
      callName: 'postScheduleVisit',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'idVisitante': idVisitante,
        'dtInicio': dtInicio,
        'dtFim': dtFim,
        'unica': unica,
        'idMotivo': idMotivo,
        'idNAC': idNAC,
        'Obs': obs,
        'DevDesc': devDesc,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  String? errorMsg(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.error_msg''',
      ));
}

class GetScheduleVisitCall {
  Future<ApiCallResponse> call({
    final int? pageSize,
    final int? pageNumber,
    final String? chaveBusca,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getVisitas';

    return await ApiManager.instance.makeApiCall(
      callName: 'getScheduleVisit',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliUUID,
        'atividade': atividade,
        'pageSize': pageSize,
        'pageNumber': pageNumber,
        'chaveBusca': chaveBusca ?? '',
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  String? errorMsg(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.error_msg''',
      ));
  int? totalRows(dynamic response) => castToType<int>(getJsonField(
        response,
        r'''$.total_rows''',
      ));
  List? visitas(dynamic response) => getJsonField(
        response,
        r'''$.visitas''',
        true,
      ) as List?;
  List<String>? visitaDesNome(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].DES_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaMotDescricao(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_DESCRICAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaMotDia(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_DIA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List? visitaMotHorafixa(dynamic response) => getJsonField(
        response,
        r'''$.visitas[:].MOT_HORAFIXA''',
        true,
      ) as List?;
  List<String>? visitaMotHoras(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_HORAS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaMotMinutos(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_MINUTOS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaMotTipo(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_TIPO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaNacDescricao(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].NAC_DESCRICAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVawChave(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_CHAVE''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVarDestino(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_DESTINO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVawDtCriacao(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_DTCRIACAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVawDtFIm(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_DTFIM''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVawDtInicio(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_DTINICIO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVawId(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVawObs(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_OBS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVawStatus(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_STATUS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVawUnica(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_UNICA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVteDocumentos(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_DOCUMENTO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVteEmail(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_EMAIL''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVteEmpresa(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_EMPRESA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVteNome(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVteTipo(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_TIPO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVteTelefone(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_TELEFONE''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? visitaVdoNome(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VDO_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  int? visitaTotalPages(dynamic response) => castToType<int>(getJsonField(
        response,
        r'''$.total_pages''',
      ));
  String? page(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.page''',
      ));
}

class GetDadosCall {
  Future<ApiCallResponse> call() async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getDados';

    return await ApiManager.instance
        .makeApiCall(
          callName: 'getDados',
          apiUrl: '$baseUrl/processRequest.php',
          callType: ApiCallType.POST,
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
          },
          params: {
            'devUUID': devUUID,
            'userUUID': userUUID,
            'cliID': cliUUID,
            'atividade': atividade,
          },
          bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
          returnBody: true,
          encodeBodyUtf8: false,
          decodeUtf8: false,
          cache: false,
          isStreamingApi: false,
          alwaysAllowBody: false,
        )
        .timeout(const Duration(seconds: 30));
  }

  bool? errorBolean(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  String? msgStr(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.error_msg''',
      ));
  String? visitedDesNomeStr(dynamic response) =>
      castToType<String>(getJsonField(
        response,
        r'''$.visitado.DES_NOME''',
      ));
  String? visitedVDOTIdStr(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.visitado.VDO_ID''',
      ));
  String? visitedVDOTNomeStr(dynamic response) =>
      castToType<String>(getJsonField(
        response,
        r'''$.visitado.VDO_NOME''',
      ));
  String? visitedVDOTipoStr(dynamic response) =>
      castToType<String>(getJsonField(
        response,
        r'''$.visitado.VDO_TIPO''',
      ));
  String? visitedVDOImeiStr(dynamic response) =>
      castToType<String>(getJsonField(
        response,
        r'''$.visitado.VDO_IMEI''',
      ));
  String? visitedVDODocumentoStr(dynamic response) =>
      castToType<String>(getJsonField(
        response,
        r'''$.visitado.VDO_DOCUMENTO''',
      ));
  String? visitedVDOEmailStr(dynamic response) =>
      castToType<String>(getJsonField(
        response,
        r'''$.visitado.VDO_EMAIL''',
      ));
  String? visitedVDOStatusWebStr(dynamic response) =>
      castToType<String>(getJsonField(
        response,
        r'''$.visitado.VDO_STATUSWEB''',
      ));
  List<String>? reasonsMotIdList(dynamic response) => (getJsonField(
        response,
        r'''$.motivos[:].MOT_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? reasonsMotDescStrList(dynamic response) => (getJsonField(
        response,
        r'''$.motivos[:].MOT_DESCRICAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? reasonsMotTypeStrList(dynamic response) => (getJsonField(
        response,
        r'''$.motivos[:].MOT_TIPO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? reasonsMotWebStrList(dynamic response) => (getJsonField(
        response,
        r'''$.motivos[:].MOT_WEB''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  dynamic visitedJson(dynamic response) => getJsonField(
        response,
        r'''$.visitado''',
      );
  String? visitedDescIdStr(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.visitado.DES_ID''',
      ));
  String? visitedVDoNotTerceirosStr(dynamic response) =>
      castToType<String>(getJsonField(
        response,
        r'''$.visitado.VDO_NOTTERCEIROS''',
      ));
  List? reasonsJsonList(dynamic response) => getJsonField(
        response,
        r'''$.motivos''',
        true,
      ) as List?;
  List<String>? resonsMotDiaStrList(dynamic response) => (getJsonField(
        response,
        r'''$.motivos[:].MOT_DIA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? reasonsMotHorasStrList(dynamic response) => (getJsonField(
        response,
        r'''$.motivos[:].MOT_HORAS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List? reasonsMotMinutosStrList(dynamic response) => getJsonField(
        response,
        r'''$.motivos[:].MOT_MINUTOS''',
        true,
      ) as List?;
  List? reasonsMotHoraFixaStrList(dynamic response) => getJsonField(
        response,
        r'''$.motivos[:].MOT_HORAFIXA''',
        true,
      ) as List?;
  List? levelJsonList(dynamic response) => getJsonField(
        response,
        r'''$.niveis''',
        true,
      ) as List?;
  List<String>? levelNACIdStrList(dynamic response) => (getJsonField(
        response,
        r'''$.niveis[:].NAC_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? levelNACDescricaoStrList(dynamic response) => (getJsonField(
        response,
        r'''$.niveis[:].NAC_DESCRICAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? levelNACHorIdStrList(dynamic response) => (getJsonField(
        response,
        r'''$.niveis[:].NAC_HOR_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? levelNACIndPermiteReentradaStrList(dynamic response) =>
      (getJsonField(
        response,
        r'''$.niveis[:].NAC_INDPERMITEREENTRADA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? levelNACObservacaoStrList(dynamic response) => (getJsonField(
        response,
        r'''$.niveis[:].NAC_OBSERVACAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? levelNACTempoAntiCaronaStrList(dynamic response) =>
      (getJsonField(
        response,
        r'''$.niveis[:].NAC_TEMPOANTICARONA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? levelNACTpUserStrList(dynamic response) => (getJsonField(
        response,
        r'''$.niveis[:].NAC_TPUSER''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  bool? provisionalBoolean(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.provisional''',
      ));
  bool? whatsappBoolean(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.whatsapp''',
      ));
}

class GetVisitorByDocCall {
  Future<ApiCallResponse> call({
    final String? documento,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getVisitante';

    return await ApiManager.instance.makeApiCall(
      callName: 'getVisitorByDoc',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'Documento': documento,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  String? errorMsg(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.error_msg''',
      ));
  dynamic visitante(dynamic response) => getJsonField(
        response,
        r'''$.visitante''',
      );
  String? vistanteId(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.visitante.VTE_ID''',
      ));
}

class GetFotoVisitanteCall {
  Future<ApiCallResponse> call({
    final String? documento,
    final String? tipo,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getFotoVisitante';

    return await ApiManager.instance.makeApiCall(
      callName: 'getFotoVisitante',
      apiUrl: '$baseUrl/getImage.php',
      callType: ApiCallType.GET,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'Documento': documento,
        'tipo': tipo,
      },
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

class PostProvVisitSchedulingCall {
  Future<ApiCallResponse> call({
    final String? data,
    final String? motivo,
    final String? nome,
    final String? proID,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'putAgendamentoProv';

    return await ApiManager.instance.makeApiCall(
      callName: 'postProvVisitScheduling',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'data': ValidatorUtil.toISO8601("dd/MM/yyyy HH:mm:ss", data!),
        'motivo': motivo,
        'nome': nome,
        'proID': proID,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  String? msg(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.mensagem''',
      ));
  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
}

class GetVisitsCall {
  Future<ApiCallResponse> call({
    final int? pageSize,
    final int? pageNumber,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getVisitas';

    return await ApiManager.instance.makeApiCall(
      callName: 'getVisits',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'pageSize': pageSize,
        'pageNumber': pageNumber,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  int? totalRows(dynamic response) => castToType<int>(getJsonField(
        response,
        r'''$.total_rows''',
      ));
  List? visitasList(dynamic response) => getJsonField(
        response,
        r'''$.visitas''',
        true,
      ) as List?;
  List<String>? desNome(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].DES_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? motDesc(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_DESCRICAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? motDia(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_DIA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List? motHorafixa(dynamic response) => getJsonField(
        response,
        r'''$.visitas[:].MOT_HORAFIXA''',
        true,
      ) as List?;
  List<String>? motHoras(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_HORAS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? motMinutos(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_MINUTOS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? motTipo(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].MOT_TIPO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? nACDesc(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].NAC_DESCRICAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vAWChave(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_CHAVE''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vAWDestino(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_DESTINO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vAWDTCriacao(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_DTCRIACAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vAWDTFim(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_DTFIM''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vawdtinicio(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_DTINICIO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vAWId(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vAWObs(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_OBS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vAWStatus(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_STATUS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vAWUnica(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VAW_UNICA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vTEDocumento(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_DOCUMENTO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vTEEmail(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_EMAIL''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vTEEmpresa(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_EMPRESA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vTENome(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vTETIpo(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_TIPO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vTETelefone(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VTE_TELEFONE''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? vDONome(dynamic response) => (getJsonField(
        response,
        r'''$.visitas[:].VDO_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
}

class DeleteVisitCall {
  Future<ApiCallResponse> call({
    final String? idVisita,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'cancelaVisita';

    return await ApiManager.instance.makeApiCall(
      callName: 'deleteVisit',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliID,
        'atividade': atividade,
        'idVisita': idVisita,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  String? msg(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.error_msg''',
      ));
}

class GetPessoasLocalCall {
  Future<ApiCallResponse> call() async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String ownerUUID =
        (await StorageHelper().get(ProfileStorageKey.ownerUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';

    return await ApiManager.instance.makeApiCall(
      callName: 'getPessoasLocal',
      apiUrl: '$baseUrl/getPessoasLocal.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'cliID': cliUUID,
        'ownID': ownerUUID,
        'devUUID': devUUID,
        'userUUID': userUUID,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  List? pessoas(dynamic response) => getJsonField(
        response,
        r'''$.pessoas''',
        true,
      ) as List?;
  List<String>? usuEmail(dynamic response) => (getJsonField(
        response,
        r'''$.pessoas[:].USU_EMAIL''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? usuNome(dynamic response) => (getJsonField(
        response,
        r'''$.pessoas[:].USU_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
}

class RespondeSolicitacaoCall {
  Future<ApiCallResponse> call({
    final String? referencia,
    final String? tarefa,
    final String? resposta,
    final String? idVisitante,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'respondeSolicitacao';

    return await ApiManager.instance.makeApiCall(
      callName: 'respondeSolicitacao',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'userUUID': userUUID,
        'devUUID': devUUID,
        'cliID': cliUUID,
        'atividade': atividade,
        'referencia': referencia,
        'tarefa': tarefa,
        'resposta': resposta,
        'idVisitante': idVisitante,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  String? msg(dynamic response) => castToType<String>(getJsonField(
        response,
        r'''$.error_msg''',
      ));
}

class GetAccessCall {
  Future<ApiCallResponse> call({
    final String? pageSize,
    final String? pageNumber,
    final String? pesTipo,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getAcessos';

    return await ApiManager.instance.makeApiCall(
      callName: 'getAccess',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliUUID,
        'atividade': atividade,
        'pageSize': pageSize,
        'pageNumber': pageNumber,
        'pesTipo': pesTipo,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  int? rows(dynamic response) => castToType<int>(getJsonField(
        response,
        r'''$.total_rows''',
      ));
  int? pages(dynamic response) => castToType<int>(getJsonField(
        response,
        r'''$.total_pages''',
      ));
  int? page(dynamic response) => castToType<int>(getJsonField(
        response,
        r'''$.page''',
      ));
  List? access(dynamic response) => getJsonField(
        response,
        r'''$.acessos''',
        true,
      ) as List?;
  List<String>? accessDateTime(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].ACE_DATAHORA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessType(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].ACE_TIPO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessDesc(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].ACI_DESCRICAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessID(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].ACI_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessMobileNotify(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].ACI_NOTIFICA_MOBILE''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessDestDesc(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].DEST_DESC''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessDestType(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].DEST_TIPO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessDestID(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].DEST_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessDestProID(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].DEST_PRO_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessIdenExternCode(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].IDE_CODEXTERNO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessIdenInternalCode(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].IDE_CODINTERNO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessIdenDesc(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].IDE_DESCRICAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessIdenID(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].IDE_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessIdenStatus(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].IDE_STATUS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessIdenUse(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].IDE_USO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessPersonID(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].PES_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessPersonName(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].PES_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessPersonType(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].PES_TIPO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessDescSet(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].SET_DESCRICAO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessIDSet(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].SET_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? accessTypeet(dynamic response) => (getJsonField(
        response,
        r'''$.acessos[:].SET_TIPO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
}

class GetLiberationsCall {
  Stream<ApiCallResponse> call() {
    final String baseUrl = PhpGroup.getBaseUrl();
    final StreamController<ApiCallResponse> controller = StreamController();

    Future.microtask(() async {
      final String devUUID =
          (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
      final String userUUID =
          (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
      final String cliUUID =
          (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
      const String atividade = 'getSolicitacoes';

      try {
        final response = await ApiManager.instance.makeApiCall(
          callName: 'getLiberations',
          apiUrl: '$baseUrl/processRequest.php',
          callType: ApiCallType.POST,
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
          },
          params: {
            'devUUID': devUUID,
            'userUUID': userUUID,
            'cliID': cliUUID,
            'atividade': atividade,
          },
          bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
          returnBody: true,
          encodeBodyUtf8: false,
          decodeUtf8: false,
          cache: false,
          isStreamingApi: false,
          alwaysAllowBody: false,
        );
        controller.add(response);
        await controller.close();
      } catch (e) {
        controller.addError(e);
        await controller.close();
      }
    });

    return controller.stream;
  }

  bool? error(dynamic response) => castToType<bool>(getJsonField(
        response,
        r'''$.error''',
      ));
  List? rqList(dynamic response) => getJsonField(
        response,
        r'''$.solicitacoes''',
        true,
      ) as List?;
  List<String>? rqNotID(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotDest(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_DESTINO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotSendDate(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_DTENVIO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotReceiveDate(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_DTRESPOSTA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotEmailAnswer(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_EMAILRESPOSTA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotReason(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_MOTIVO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotSendMsg(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_MSGENVIO''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotReceiveMsg(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_MSGRESPOSTA''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotName(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotOperator(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_OPERADOR''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotStatus(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_STATUS''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqNotVTE(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].NOT_VISITANTE''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqVteID(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].VTE_ID''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqVteName(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].VTE_NOME''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
  List<String>? rqVteRG(dynamic response) => (getJsonField(
        response,
        r'''$.solicitacoes[:].VTE_RG''',
        true,
      ) as List?)
          ?.withoutNulls
          .map((x) => castToType<String>(x))
          .withoutNulls
          .toList();
}

class GetMessagesCall {
  Future<ApiCallResponse> call({
    final String? pageSize,
    final String? pageNumber,
    final String? tipoDestino,
  }) async {
    final String baseUrl = PhpGroup.getBaseUrl();

    final String devUUID =
        (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    final String userUUID =
        (await StorageHelper().get(ProfileStorageKey.userUUID.key)) ?? '';
    final String cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    const String atividade = 'getMensagens';

    return await ApiManager.instance.makeApiCall(
      callName: 'getMessages',
      apiUrl: '$baseUrl/processRequest.php',
      callType: ApiCallType.POST,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      params: {
        'devUUID': devUUID,
        'userUUID': userUUID,
        'cliID': cliUUID,
        'atividade': atividade,
        'pageSize': pageSize,
        'pageNumber': pageNumber,
        'tipoDestino': tipoDestino,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
      encodeBodyUtf8: false,
      decodeUtf8: false,
      cache: false,
      isStreamingApi: false,
      alwaysAllowBody: false,
    );
  }
}

/// End PHP Group Code

class ApiPagingParams {
  int nextPageNumber = 0;
  int numItems = 0;
  dynamic lastResponse;

  ApiPagingParams({
    required this.nextPageNumber,
    required this.numItems,
    required this.lastResponse,
  });

  @override
  String toString() =>
      'PagingParams(nextPageNumber: $nextPageNumber, numItems: $numItems, lastResponse: $lastResponse,)';
}

String _toEncodable(dynamic item) {
  return item;
}

String _serializeList(List? list) {
  list ??= <String>[];
  try {
    return json.encode(list, toEncodable: _toEncodable);
  } catch (_) {
    if (kDebugMode) {}
    return '[]';
  }
}

String _serializeJson(dynamic jsonVar, [bool isList = false]) {
  jsonVar ??= (isList ? [] : {});
  try {
    return json.encode(jsonVar, toEncodable: _toEncodable);
  } catch (_) {
    if (kDebugMode) {}
    return isList ? '[]' : '{}';
  }
}
