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.IupKkoPayAbleService;
import cokr.xit.ens.biz.iup.billpay.service.process.IupKkoPayNoticeService;
import cokr.xit.ens.biz.iup.billpay.service.process.IupKkoPayResultService;
import cokr.xit.ens.biz.iup.billpay.service.process.IupKkoPayUrlService;
import cokr.xit.ens.core.exception.code.EnsErrCd;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.kko.service.process.model.KkoPayNoticeRespData;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.kko.service.process.model.KkoPayUrlRespData;
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 IupKkoPayUseSysServiceImpl implements IupPayUseSysService<PayApiRespDTO, Map<String, Object>> {

    private final IupKkoPayUrlService iupKkoPayUrlService;
    private final IupKkoPayNoticeService iupKkoPayNoticeService;
    private final IupKkoPayAbleService iupKkoPayAbleService;
    private final IupKkoPayResultService iupKkoPayResultService;

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

        pay.exec();

        return pay.getResult();
    }

    @Override
    public PayApiRespDTO payNotice(Map<String, Object> param) {
        Pay<PayApiRespDTO<KkoPayNoticeRespData>> pay = PayHelper.<Map<String, Object>, Map<String, Object>, PayApiRespDTO<KkoPayNoticeRespData>>builder()
                .param(param)
                .payHelperService(iupKkoPayNoticeService)
                .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(iupKkoPayAbleService)
                .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(iupKkoPayResultService)
                .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();
    }
}
