package com.qsoft.rs.sincoar.dominio.mapper;

import com.qsoft.rs.sincoar.dto.MigrlogDTO;
import com.qsoft.rs.sincoar.model.Migrlog;
import java.math.BigDecimal;
import java.math.BigInteger;
import javax.annotation.processing.Generated;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2022-09-02T16:14:51-0500",
    comments = "version: 1.5.2.Final, compiler: javac, environment: Java 17.0.4 (Private Build)"
)
public class MigrlogMapperImpl implements MigrlogMapper {

    @Override
    public Migrlog getEntidad(MigrlogDTO migrlog) {
        if ( migrlog == null ) {
            return null;
        }

        Migrlog migrlog1 = new Migrlog();

        migrlog1.setParentLogId( migrlogDTOToMigrlog( migrlog ) );
        if ( migrlog.getId() != null ) {
            migrlog1.setId( BigDecimal.valueOf( migrlog.getId() ) );
        }
        migrlog1.setLogDate( migrlog.getLogDate() );
        if ( migrlog.getSeverity() != null ) {
            migrlog1.setSeverity( migrlog.getSeverity().shortValue() );
        }
        migrlog1.setLogtext( migrlog.getLogtext() );
        migrlog1.setPhase( migrlog.getPhase() );
        if ( migrlog.getRefObjectId() != null ) {
            migrlog1.setRefObjectId( BigInteger.valueOf( migrlog.getRefObjectId() ) );
        }
        migrlog1.setRefObjectType( migrlog.getRefObjectType() );
        if ( migrlog.getConnectionIdFk() != null ) {
            migrlog1.setConnectionIdFk( BigInteger.valueOf( migrlog.getConnectionIdFk() ) );
        }

        return migrlog1;
    }

    @Override
    public MigrlogDTO getDto(Migrlog migrlog) {
        if ( migrlog == null ) {
            return null;
        }

        MigrlogDTO migrlogDTO = new MigrlogDTO();

        BigDecimal id = migrlogParentLogIdId( migrlog );
        if ( id != null ) {
            migrlogDTO.setParentLogId( id.intValue() );
        }
        if ( migrlog.getId() != null ) {
            migrlogDTO.setId( migrlog.getId().intValue() );
        }
        migrlogDTO.setLogDate( migrlog.getLogDate() );
        migrlogDTO.setSeverity( (int) migrlog.getSeverity() );
        migrlogDTO.setLogtext( migrlog.getLogtext() );
        migrlogDTO.setPhase( migrlog.getPhase() );
        if ( migrlog.getRefObjectId() != null ) {
            migrlogDTO.setRefObjectId( migrlog.getRefObjectId().intValue() );
        }
        migrlogDTO.setRefObjectType( migrlog.getRefObjectType() );
        if ( migrlog.getConnectionIdFk() != null ) {
            migrlogDTO.setConnectionIdFk( migrlog.getConnectionIdFk().intValue() );
        }

        return migrlogDTO;
    }

    protected Migrlog migrlogDTOToMigrlog(MigrlogDTO migrlogDTO) {
        if ( migrlogDTO == null ) {
            return null;
        }

        Migrlog migrlog = new Migrlog();

        if ( migrlogDTO.getParentLogId() != null ) {
            migrlog.setId( BigDecimal.valueOf( migrlogDTO.getParentLogId() ) );
        }

        return migrlog;
    }

    private BigDecimal migrlogParentLogIdId(Migrlog migrlog) {
        if ( migrlog == null ) {
            return null;
        }
        Migrlog parentLogId = migrlog.getParentLogId();
        if ( parentLogId == null ) {
            return null;
        }
        BigDecimal id = parentLogId.getId();
        if ( id == null ) {
            return null;
        }
        return id;
    }
}
