package com.banesco.application.helper;


import com.banesco.common.application.exception.BanRuntimeException;
import com.banesco.common.domain.dto.bian.device.StringHelper;
import com.banesco.commons.config.StatusCodes;
import com.banesco.domain.bian.request.BusUpdateCardStatusRequest;
import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class UpdateCardStatusRequestValidator {

    // Function to check invalid fields
    public void validatedRequest(
            BusUpdateCardStatusRequest request
    ) {

        if (request == null) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "body");
        }
        //check header
        if (StringHelper.isEmpty(request.getCustomerReferenceFintechId())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "customerReferenceFintechId");
        }

        if (StringHelper.isEmpty(request.getRequestId())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "requestId");
        }


        //  Device
        if (request.getDevice() == null) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "device");
        }

        if (StringHelper.isEmpty(request.getDevice().getDeviceType())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "device.deviceType");
        }

        if (StringHelper.isEmpty(request.getDevice().getDeviceDescription())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "device.deviceDescription");
        }


        if (StringHelper.isEmpty(request.getDevice().getDeviceSessionReference())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "device.deviceSessionReference");
        }


        // Customer

        var customerReference = request.getCustomerReference();
        if (customerReference == null) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "customerReference");
        }

        if (StringHelper.isEmpty(customerReference.getCustomerIdType())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "customerReference.customerIdType");
        }

        // Card


        var paymentCard = request.getCardReference();
        if (paymentCard == null) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "cardReference.paymentCard");
        }

        if (StringHelper.isEmpty(paymentCard.getCardType())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "cardReference.cardType");
        }


        if (StringHelper.isEmpty(paymentCard.getCardNumber())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "cardReference.cardNumber");
        }


        if (StringHelper.isEmpty(paymentCard.getCardStatusCode())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "cardReference.cardStatusCode");
        }

        if (StringHelper.isEmpty(paymentCard.getCardStatusAction())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "cardReference.cardStatusAction");
        }


        if (StringHelper.isEmpty(paymentCard.getCardStatusReason())) {
            throw new BanRuntimeException(StatusCodes.FIELD_REQUIRED, "cardReference.cardStatusReason");
        }


    }

}
