package eu.reply.lea.services.yard.boundary.rest.yard;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Default;
import jakarta.inject.Inject;

import eu.reply.lea.services.yard.boundary.rest.yard.action.SendToDockAction;
import eu.reply.lea.services.yard.boundary.rest.yard.action.SendToZoneAction;
import eu.reply.lea.services.yard.domainservice.LogisticUnitDomainService;
import eu.reply.sce.backend.core.entity.JsonEntityReference;
import eu.reply.sce.backend.core.jee.client.ServiceClient;
import eu.reply.sce.backend.core.jee.log.Logged;

@ApplicationScoped
@Default
@Logged
public class LogisticUnitServiceImpl implements LogisticUnitDomainService {

    @Inject
    private ServiceClient serviceClient;


    @Override
    public void createTaskSendToDock(final JsonEntityReference yardElementReference, final JsonEntityReference locationReference,
                                     final boolean loading, final boolean unloading) {
        if (!locationReference.getEntityName().equals("Dock")) {
            throw new RuntimeException("Unknown location reference: " + locationReference.getEntityName());
        }
        serviceClient.action(yardElementReference, "sendToDock", new SendToDockAction(locationReference, loading, unloading));

    }

    @Override
    public void createTaskSendToZone(final JsonEntityReference yardElementReference, final JsonEntityReference locationReference, final String loadingUnitActivityType) {
        if (!locationReference.getEntityName().equals("Zone")) {
            throw new RuntimeException("Unknown location reference: " + locationReference.getEntityName());
        }
        serviceClient.action(yardElementReference, "sendToZone", new SendToZoneAction(locationReference, loadingUnitActivityType));
    }
    
    public String convertToYardActivityType(final String loadingUnitActivityType){
        if (loadingUnitActivityType == null || loadingUnitActivityType.isEmpty()) {
            return null;
        }
        return switch (loadingUnitActivityType) {
            case "GENERIC" -> "WEIGHING_GENERIC";
            case "INBOUND" -> "WEIGHING_INBOUND";
            case "OUTBOUND" -> "WEIGHING_OUTBOUND";
            default -> throw new RuntimeException("Unknown loading activity type: " + loadingUnitActivityType);
        };
    }
}
public class YardContentProcessor {

    @Inject
    @ModuleConfiguration.Module(eu.reply.lea.services.yard.ModuleConfiguration.MODULE_NAME)
    private EntityManager em;

    @Inject
    private YardContentMovementDomainService yardContentMovementDomainService;

    @Inject
    private LogisticUnitDomainService logisticUnitDomainService;

    public void persisted(final YardContent yardContent) {
        // refresh location
    }

    public YardContent action(final YardContent yardContent, final YardContentMoveToDockAction action) {
        YardLocation destination = em.find(YardLocation.class, action.getDestination().getId());
        logisticUnitDomainService.createTaskSendToDock(yardContent.getLogisticUnit(), destination.getElement().getYardElement(), action.isLoading(),
            action.isUnloading());
        return yardContent;
    }

    public YardContent action(final YardContent yardContent, final YardContentMoveToZoneAction action) {
        YardLocation destination = em.find(YardLocation.class, action.getDestination().getId());
        logisticUnitDomainService.createTaskSendToZone(yardContent.getLogisticUnit(), destination.getElement().getYardElement(), getWeighingType(action) );
        return yardContent;
    }

    public String getWeighingType(final YardContentMoveToZoneAction action) {
        if (action.isGenericWeight()){
            return "GENERIC";
        }else if (action.isOutboundWeight()){
            return "OUTBOUND";
        }else if (action.isInboundWeight()){
            return "INBOUND";
        }else {
            return null;
        }
    }

    public YardContent out(final YardContent yardContent) {
        yardContentMovementDomainService.out(yardContent, Instant.now());
        return yardContent;
    }
}
The processor is an api rest . In this case we take information from the request and then we call another java service (which implementation is inside the infrastructure layer) which calls another microservice which does the actual action

what would you do differently following ddd principles