package cokr.xit.ens.modules.common.ctgy.intgrnbill.nv.service;

import cokr.xit.ens.core.exception.EnsException;
import cokr.xit.ens.core.exception.code.EnsErrCd;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.nv.entity.BillNvEasyPay;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.nv.service.process.NvPayAbleService;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.nv.service.process.NvPayCancelService;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.nv.service.process.NvPayNoticeService;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.nv.service.process.NvPayResultService;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.nv.service.process.model.NvPayNoticeRespData;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.service.process.Pay;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.service.process.PayProcessService;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.model.PayApiRespDTO;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.service.process.model.PayAbleData;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.service.process.model.PayCancelData;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.service.process.model.PayNoticeData;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.service.process.model.PayResultData;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.service.process.template.PayHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import java.util.Map;

@Log4j2
@RequiredArgsConstructor
@Service
public class NvPayProcessService implements PayProcessService<PayApiRespDTO, Map<String, Object>> {
    private final NvPayNoticeService nvPayNoticeService;
    private final NvPayAbleService nvPayAbleService;
    private final NvPayResultService nvPayResultService;
    private final NvPayCancelService nvPayCancelService;

    @Override
    public PayApiRespDTO gnrUrl(Map<String, Object> stringObjectMap) {
        throw new EnsException(EnsErrCd.SERVICE_NOT_SUPPORTED, EnsErrCd.SERVICE_NOT_SUPPORTED.getCodeNm());
    }

    @Override
    public PayApiRespDTO payNotice(Map<String, Object> data) {
        String billUid = (String) data.get("billUid");

        
        Pay<PayApiRespDTO<NvPayNoticeRespData>> pay = PayHelper.<PayNoticeData<BillNvEasyPay>, String, PayApiRespDTO<NvPayNoticeRespData>>builder()
                .param(billUid)
                .payHelperService(nvPayNoticeService)
                .build();

        
        pay.exec();

        return pay.getResult();
    }

    @Override
    public PayApiRespDTO payAble(Map<String, Object> data) {

        
        Pay<PayApiRespDTO<Map<String, Object>>> pay = PayHelper.<PayAbleData<BillNvEasyPay>, Map<String, Object>, PayApiRespDTO<Map<String, Object>>>builder()
                .param(data)
                .payHelperService(nvPayAbleService)
                .build();

        
        pay.exec();

        return pay.getResult();
    }

    @Override
    public PayApiRespDTO payResult(Map<String, Object> data) {

        
        Pay<PayApiRespDTO<Map<String, Object>>> pay = PayHelper.<PayResultData<BillNvEasyPay>, Map<String, Object>, PayApiRespDTO<Map<String, Object>>>builder()
                .param(data)
                .payHelperService(nvPayResultService)
                .build();

        
        pay.exec();

        return pay.getResult();
    }

    @Override
    public PayApiRespDTO payCancel(Map<String, Object> data) {

        
        Pay<PayApiRespDTO<Map<String, Object>>> pay = PayHelper.<PayCancelData<BillNvEasyPay>, Map<String, Object>, PayApiRespDTO<Map<String, Object>>>builder()
                .param(data)
                .payHelperService(nvPayCancelService)
                .build();

        
        pay.exec();

        return pay.getResult();
    }
}
