package cokr.xit.ens.biz.iup.signtalk.service.support.accept;

import cokr.xit.ens.biz.iup.domain.TbInputDataXit;
import cokr.xit.ens.core.utils.DateUtil;
import cokr.xit.ens.modules.nvsigntalk.model.config.DocumentConfNvSt;
import lombok.RequiredArgsConstructor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@RequiredArgsConstructor
public class AcptDocNvSt implements Accept<DocumentConfNvSt> {

    private final TbInputDataXit tbInputDataXit;
    private final String orgId;
    private final String redirectUrl;

    @Override
    public DocumentConfNvSt createDocument() {
//        int days = DateUtil.daysByFromBetweenTo(LocalDateTime.now(), tbInputDataXit.getTbInputXit().getPayExpiresDt());
        return DocumentConfNvSt.builder()
//                .valid_duration(DateUtil.daysToRelTime(days) / 1000)
                .valid_duration_at(DateUtil.dateToAbsTimeSec(tbInputDataXit.getTbInputXit().getPayExpiresDt().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))))
//                .redirect_url(tbInputDataXit.getPayUrl())
                .redirect_url(redirectUrl)
                .publish_document_yn("y")
                .document_hash(null)
                .call_center_no(tbInputDataXit.getCallCenterNo())
                .org_id(orgId)
                .auth_require_yn("y")
                .notification(null)
                .calculation_key(null)
                .category_key(null)
                .document_key(null)
                .build();
    }
}
