package com.bcxin.tenant.domain.events.handlers;

import com.bcxin.Infrastructures.components.EventDispatcher;
import com.bcxin.Infrastructures.events.handlers.DomainEventHandlerAbstract;
import com.bcxin.tenant.domain.events.EmployeeBeforeEntryValidationByIdentityEvent;
import com.bcxin.tenant.domain.readers.TenantDbReader;
import org.springframework.stereotype.Component;

@Component
public class EmployeeBeforeEntryValidationByIdNumEvent_ValidationHandler extends DomainEventHandlerAbstract<EmployeeBeforeEntryValidationByIdentityEvent> {
    private final TenantDbReader dbReader;
    private final EventDispatcher eventDispatcher;

    public EmployeeBeforeEntryValidationByIdNumEvent_ValidationHandler(TenantDbReader dbReader, EventDispatcher eventDispatcher) {
        this.dbReader = dbReader;
        this.eventDispatcher = eventDispatcher;
    }

    @Override
    protected void execute(EmployeeBeforeEntryValidationByIdentityEvent event) {

        /*
        Collection<EmployeeTenantUserIdNumDto> tenantUserIdNums =
                this.dbReader.getTenantUserIdMapByIdNums(event.getIdNums());

        Collection<EmployeeBeforeEntryValidationEvent.TenantUserOccupationTypeInfo> tenantUsers
                = event.getIdCardOccupationTypeInfos().stream().map(ii -> {
            Optional<EmployeeTenantUserIdNumDto> selectTenantUserMapOptional
                    = tenantUserIdNums.stream().filter(ix -> ix.getIdNum().equalsIgnoreCase(ii.getIdNum()))
                    .findFirst();

            if (!selectTenantUserMapOptional.isPresent()) {
                return null;
            }

            return EmployeeBeforeEntryValidationEvent.TenantUserOccupationTypeInfo.create(
                    selectTenantUserMapOptional.get().getTenantUserId(),
                    ii.getOccupationType());
        }).collect(Collectors.toList());

        this.eventDispatcher.dispatch(
                EmployeeBeforeEntryValidationEvent.create(
                        event.getAreaCode(), tenantUsers
                ));
         */
    }
}
