import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/LacumAccountInformation.dart';

import 'lacum-service.dart';

class LacumTransferService extends LacumService{
  LacumAccountInformation lacumReceiverInformation;

  Future getLacumGroupDataBuAccountId(String accountId) async {
    hasError = false;
    super.error = "";

    Map<String, dynamic> body = Map();
    body['IdentificationNo'] = user.patientIdentificationNo;
    body['AccountNumber'] = accountId;

    try {
      await baseAppClient.post(GET_LACUM_GROUP_INFORMATION,
          onSuccess: (response, statusCode) async {
            lacumReceiverInformation =  LacumAccountInformation.fromJson(response);
          }, onFailure: (String error, int statusCode) {
            hasError = true;
            super.error = error;
            return null;
          }, body: body);
    } catch (error) {
      throw error;
    }
  }

  Future transferYaHalaLoyaltyPoints(String points) async {
    hasError = false;
    super.error = "";

    Map<String, dynamic> body = Map();
    body['MobileNo'] = lacumGroupInformation.lakumInquiryInformationObjVersion.mobileNumber;
    body['UserName'] = lacumGroupInformation.lakumInquiryInformationObjVersion.memberName;
    body['YaHalaSenderAccNumber'] = lacumGroupInformation.lakumInquiryInformationObjVersion.accountNumber;
    body['Yahala_IdentificationNo'] = lacumGroupInformation.lakumInquiryInformationObjVersion.memberUniversalId;
    body['YaHalaPointsToTransfer'] = points;
    body['YaHalaReceiverAccNumber'] = lacumReceiverInformation.lakumInquiryInformationObjVersion.accountNumber;
    body['YaHalaReceiverMobileNumber'] = lacumReceiverInformation.lakumInquiryInformationObjVersion.mobileNumber;
    body['YaHalaReceiverName'] = lacumReceiverInformation.lakumInquiryInformationObjVersion.memberName;

    try {
      await baseAppClient.post(TRANSFER_YAHALA_LOYALITY_POINTS,
          onSuccess: (response, statusCode) async {
          }, onFailure: (String error, int statusCode) {
            hasError = true;
            super.error = error;
          }, body: body);
    } catch (error) {
      throw error;
    }
  }

}