package cokr.xit.ens.biz.iup.billpay.service.impl;

import cokr.xit.ens.biz.iup.billpay.service.IupPayUseSysService;
import cokr.xit.ens.biz.iup.billpay.service.process.IupNvPayAbleService;
import cokr.xit.ens.biz.iup.billpay.service.process.IupNvPayCancelService;
import cokr.xit.ens.biz.iup.billpay.service.process.IupNvPayNoticeService;
import cokr.xit.ens.biz.iup.billpay.service.process.IupNvPayResultService;
import cokr.xit.ens.core.exception.code.EnsErrCd;
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.model.PayApiRespDTO;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.service.process.template.PayHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;


@Slf4j
@Service
@RequiredArgsConstructor
public class IupNvPayUseSysServiceImpl implements IupPayUseSysService<PayApiRespDTO, Map<String, Object>> {

    private final IupNvPayNoticeService iupNvPayNoticeService;
    private final IupNvPayAbleService iupNvPayAbleService;
    private final IupNvPayResultService iupNvPayResultService;
    private final IupNvPayCancelService iupNvPayCancelService;

    @Override
    public PayApiRespDTO gnrUrl(Map<String, Object> param) {
        return PayApiRespDTO.errBuilder()
                .resCode(EnsErrCd.SERVICE_NOT_SUPPORTED.getCode())
                .message(EnsErrCd.SERVICE_NOT_SUPPORTED.getCodeNm())
                .build();
    }

    @Override
    public PayApiRespDTO payNotice(Map<String, Object> param) {
        Pay<PayApiRespDTO<NvPayNoticeRespData>> pay = PayHelper.<Map<String, Object>, Map<String, Object>, PayApiRespDTO<NvPayNoticeRespData>>builder()
                .param(param)
                .payHelperService(iupNvPayNoticeService)
                .build();

        pay.exec();

        return pay.getResult();
    }

    @Override
    public PayApiRespDTO payAble(Map<String, Object> param) {
        Pay<PayApiRespDTO<Map<String, Object>>> pay = PayHelper.<Map<String, Object>, Map<String, Object>, PayApiRespDTO<Map<String, Object>>>builder()
                .param(param)
                .payHelperService(iupNvPayAbleService)
                .build();

        pay.exec();

        return pay.getResult();
    }

    @Override
    public PayApiRespDTO payResult(Map<String, Object> param) {
        Pay<PayApiRespDTO<Map<String, Object>>> pay = PayHelper.<Map<String, Object>, Map<String, Object>, PayApiRespDTO<Map<String, Object>>>builder()
                .param(param)
                .payHelperService(iupNvPayResultService)
                .build();

        pay.exec();

        return pay.getResult();
    }

    @Override
    public PayApiRespDTO payCancel(Map<String, Object> param) {
        return PayApiRespDTO.errBuilder()
                .resCode(EnsErrCd.SERVICE_NOT_SUPPORTED.getCode())
                .message(EnsErrCd.SERVICE_NOT_SUPPORTED.getCodeNm())
                .build();
    }
}
