package com.banesco.module.docservice_file_audit_trace.infrastructure.mapper;

import com.banesco.common.domain.model.Identifier;
import com.banesco.module.payment_file.domain.dto.request.PaymentFileRequest;
import com.banesco.module.payment_file.domain.model.Operation;
import com.banesco.module.payment_file.domain.model.PaymentFile;
import com.banesco.module.docservice_file_audit_trace.domain.dto.request.DocserviceFileAuditTraceRequest;
import com.banesco.module.docservice_file_audit_trace.domain.model.DocumentService;
import com.banesco.module.transaction.domain.model.*;

import java.util.List;

public class ServicingIssueMapper {

    private ServicingIssueMapper() {}

    public static PaymentFileRequest toPaymentRequest(
        DocserviceFileAuditTraceRequest request
    ) {
        return PaymentFileRequest.builder()
            .fintechId(request.getCustomerReferenceFintechId())
            .operation(
                Operation.builder()
                    .name(request.getDocumentName())
                    .directorio(request.getDocumentDirectory())
                    .build()
            )
            .channelOrigin(request.getChannelCode())
            .build();
    }

    public static DocumentService toModel(PaymentFile response) {
        return DocumentService.builder()
            .transaction(buildTransaction(response))
            .build();
    }

    private static Transaction buildTransaction(PaymentFile response) {
        return Transaction.builder()
            .transactionIdentification(
                Identifier.builder()
                    .identifierValue(String.valueOf(response.getId()))
                    .build()
            )
            .transactionDate(buildTransactionDateTimeList(response))
            .build();
    }

    private static List<TransactionDateTime> buildTransactionDateTimeList(PaymentFile response) {
        return List.of(
            TransactionDateTime.builder()
                .dateType(TransactionDateTimeType.INITIATED_DATE)
                .date(response.getDateCreate())
                .build()
        );
    }
}