package com.banesco.module.service_order_payment_search.domain.dto.request;

import com.banesco.module.instruction.domain.model.Instruction;
import com.banesco.module.instruction.domain.model.InstructionPurposeType;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.*;

import java.util.Map;
import java.util.Objects;

import static java.util.Map.entry;

@Getter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@RegisterForReflection
public class ServiceOrderPaymentSearchRequest {
    @NonNull
    private String customerReferenceFintechId;
    @NonNull
    private String appId;
    @NonNull
    private Instruction procedureRequest;

    public String getPartyId() {
        return getProcedureRequest()
            .getInstructionInvolvement()
            .getPartyReference()
            .getPartyIdentification()
            .get(0)
            .getPartyIdentification()
            .getIdentifierValue();
    }

    public String getInitiatedDate() {
        return getProcedureRequest()
            .getInstructionDate()
            .get(0)
            .getDate();
    }

    public String getPaymentRequestId() {
        return getProcedureRequest()
            .getInstructionIdentifier()
            .getIdentification()
            .getIdentifierValue();
    }

    public String getChannelCode() {
        return getProcedureRequest().getInstructionPurposeType().name();
    }

    public boolean isBole() {
        return getProcedureRequest().getInstructionPurposeType() == InstructionPurposeType.BOLE;
    }

    public Map<String, String> toParams() {
        return Map.ofEntries(
            entry("partyReferenceId", Objects.toString(getPartyId(), "")),
            entry("channelCode", Objects.toString(getChannelCode(), ""))
        );
    }

    public Map<String, String> toQueryString() {
        return Map.ofEntries(
            entry("appId", Objects.toString(getAppId(), "")),
            entry("customerReferenceFintechId", Objects.toString(getCustomerReferenceFintechId(), "")),
            entry("initiatedDate", Objects.toString(getInitiatedDate(), "")),
            entry("paymentRequestId", Objects.toString(getPaymentRequestId(), ""))
        );
    }
}