package com.banesco.infrastructure.mapper;

import com.banesco.application.UpdateCardStatusRequest;
import com.banesco.commons.soap.client.apidebitcardoutappsvc.BlockUnblockDebitCardRq;
import com.banesco.commons.soap.client.apidebitcardoutappsvc.ObjectFactory;
import jakarta.enterprise.context.ApplicationScoped;


@ApplicationScoped
public class DebitCardMapper {
    public final ObjectFactory objectFactory;

    public DebitCardMapper() {
        this.objectFactory = new ObjectFactory();
    }

    public BlockUnblockDebitCardRq toBlockUnblockDebitCardRequest(UpdateCardStatusRequest customerRequest) {

        BlockUnblockDebitCardRq request = objectFactory.createBlockUnblockDebitCardRq();
        request.setMsgRqHdr(customerRequest.getMsgRqHdr());

        BlockUnblockDebitCardRq.Card cardRq = objectFactory.createBlockUnblockDebitCardRqCard();

        // number card
        BlockUnblockDebitCardRq.Card.CardInfo cardInfo = objectFactory.createBlockUnblockDebitCardRqCardCardInfo();
        cardInfo.setCardNum(customerRequest.getCardReference().getCardNumber());


        BlockUnblockDebitCardRq.Card.CardInfo.Customer customer = objectFactory.createBlockUnblockDebitCardRqCardCardInfoCustomer();

        // customer
        BlockUnblockDebitCardRq.Card.CardInfo.Customer.PersonInfo.GovIssueIdent govIssueIdent = new BlockUnblockDebitCardRq.Card.CardInfo.Customer.PersonInfo.GovIssueIdent();
        govIssueIdent.setGovIssueIdentType(customerRequest.getCustomerReference().getCustomerIdType());
        govIssueIdent.setIdentSerialNum(customerRequest.getCustomerReference().getCustomerId());

        BlockUnblockDebitCardRq.Card.CardInfo.Customer.PersonInfo personInfo = objectFactory.createBlockUnblockDebitCardRqCardCardInfoCustomerPersonInfo();
        personInfo.getGovIssueIdent().add(govIssueIdent);
        customer.getPersonInfo().add(personInfo);
        cardInfo.getCustomer().add(customer);
        //bank Id
        cardInfo.setBankId(customerRequest.getMsgRqHdr().getNetworkTrnInfo().get(0).getBankId());
        cardRq.getCardInfo().add(cardInfo);


        // Status
        BlockUnblockDebitCardRq.Card.CardStatus cardStatus = new BlockUnblockDebitCardRq.Card.CardStatus();
        cardStatus.setCardStatusCode(customerRequest.getCardReference().getCardStatusCode());
        cardStatus.setCardStatusAction(customerRequest.getCardReference().getCardStatusAction());
        cardStatus.setStatusReason(customerRequest.getCardReference().getCardStatusReason());
        cardRq.getCardStatus().add(cardStatus);

        request.getCard().add(cardRq);

        return request;

    }
}
