package org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.persistence;

import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.internal.network.penetration.mapping.LazyInternalNetworkPenetrationMapping;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.internal.network.penetration.mapping.LazyInternalNetworkPenetrationMappingRepository;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.entity.LazyInternalNetworkPenetrationMappingDO;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.converter.LazyInternalNetworkPenetrationMappingConverter;

import java.util.List;
import java.util.stream.Collectors;

/**
 * describe 内网穿透映射
 *
 * @author Jia wei Wu
 * @date 2023/12/29 05:21 下午
 * @see DefaultDDDLazyInfrastructurePersistence
 **/
@Repository
public class LazyInternalNetworkPenetrationMappingRepositoryImpl implements LazyInternalNetworkPenetrationMappingRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增内网穿透映射
     *
     * @param lazyInternalNetworkPenetrationMapping 新增内网穿透映射
     * @return {@link Result<  LazyInternalNetworkPenetrationMapping  >} 内网穿透映射新增后领域对象
     * @author Jia wei Wu
     * @date 2023/12/29 05:21 下午
     **/

    @Override
    public Result<LazyInternalNetworkPenetrationMapping> story(LazyInternalNetworkPenetrationMapping lazyInternalNetworkPenetrationMapping) {
        LazyInternalNetworkPenetrationMappingDO lazyInternalNetworkPenetrationMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkPenetrationMapping);
        lazyInternalNetworkPenetrationMappingDO.setIsDeleted(false);
        lazyLambdaStream.upsertRemoveNull(lazyInternalNetworkPenetrationMappingDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增内网穿透映射
     *
     * @param lazyInternalNetworkPenetrationMappingList 批量新增内网穿透映射
     * @return {@link Result<List< LazyInternalNetworkPenetrationMapping >>} 内网穿透映射新增后领域对象集合
     * @author Jia wei Wu
     * @date 2023/12/29 05:21 下午
     **/

    @Override
    public Result<List<LazyInternalNetworkPenetrationMapping>> batchStory(List<LazyInternalNetworkPenetrationMapping> lazyInternalNetworkPenetrationMappingList) {
        List<LazyInternalNetworkPenetrationMappingDO> lazyInternalNetworkPenetrationMappingDOList = lazyInternalNetworkPenetrationMappingList.stream().map(LazyInternalNetworkPenetrationMappingConverter.INSTANCE::fromInternalNetworkPenetrationMapping).collect(Collectors.toList());
        lazyLambdaStream.upsert(lazyInternalNetworkPenetrationMappingDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个内网穿透映射
     *
     * @param lazyInternalNetworkPenetrationMapping 查询单个内网穿透映射
     * @return {@link Result< LazyInternalNetworkPenetrationMapping >} 内网穿透映射领域对象
     * @author Jia wei Wu
     * @date 2023/12/29 05:21 下午
     **/

    @Override
    public Result<LazyInternalNetworkPenetrationMapping> findOne(LazyInternalNetworkPenetrationMapping lazyInternalNetworkPenetrationMapping) {
        LazyInternalNetworkPenetrationMappingDO lazyInternalNetworkPenetrationMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkPenetrationMapping);
        LazyInternalNetworkPenetrationMapping lazyInternalNetworkPenetrationMappingOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(lazyInternalNetworkPenetrationMappingDO), LazyInternalNetworkPenetrationMapping.class);
        return ResultFactory.successOf(lazyInternalNetworkPenetrationMappingOne);
    }

    /**
     * describe 查询多个内网穿透映射
     *
     * @param lazyInternalNetworkPenetrationMapping 查询多个内网穿透映射
     * @return {@link Result<List< LazyInternalNetworkPenetrationMapping >>} 内网穿透映射领域对象
     * @author Jia wei Wu
     * @date 2023/12/29 05:21 下午
     **/

    @Override
    public Result<List<LazyInternalNetworkPenetrationMapping>> findList(LazyInternalNetworkPenetrationMapping lazyInternalNetworkPenetrationMapping) {
        LazyInternalNetworkPenetrationMappingDO lazyInternalNetworkPenetrationMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkPenetrationMapping);
        List<LazyInternalNetworkPenetrationMapping> lazyInternalNetworkPenetrationMappingList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(lazyInternalNetworkPenetrationMappingDO), LazyInternalNetworkPenetrationMapping.class);
        return ResultFactory.successOf(lazyInternalNetworkPenetrationMappingList);
    }

    /**
     * describe 分页查询多个内网穿透映射
     *
     * @param size                              当前页数
     * @param current                           当前页
     * @param lazyInternalNetworkPenetrationMapping 分页查询多个内网穿透映射
     * @return {@link Result<LazyPage< LazyInternalNetworkPenetrationMapping >>} 分页内网穿透映射领域对象
     * @author Jia wei Wu
     * @date 2023/12/29 05:21 下午
     **/

    @Override
    public Result<LazyPage<LazyInternalNetworkPenetrationMapping>> findPage(int size, int current, LazyInternalNetworkPenetrationMapping lazyInternalNetworkPenetrationMapping) {
        LazyInternalNetworkPenetrationMappingDO lazyInternalNetworkPenetrationMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkPenetrationMapping);
        LazyPage<LazyInternalNetworkPenetrationMapping> lazyPage = new LazyPage<>(current, size);
        LazyPage<LazyInternalNetworkPenetrationMapping> internalNetworkPenetrationMappingLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(lazyInternalNetworkPenetrationMappingDO), lazyPage, LazyInternalNetworkPenetrationMapping.class);
        return ResultFactory.successOf(internalNetworkPenetrationMappingLazyPage);
    }

    /**
     * describe 删除内网穿透映射
     *
     * @param lazyInternalNetworkPenetrationMapping 删除内网穿透映射
     * @return {@link Result< LazyInternalNetworkPenetrationMapping >} 内网穿透映射
     * @author Jia wei Wu
     * @date 2023/12/29 05:21 下午
     **/

    @Override
    public Result<LazyInternalNetworkPenetrationMapping> remove(LazyInternalNetworkPenetrationMapping lazyInternalNetworkPenetrationMapping) {
        LazyInternalNetworkPenetrationMappingDO lazyInternalNetworkPenetrationMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkPenetrationMapping);
        lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(lazyInternalNetworkPenetrationMappingDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在内网穿透映射
     *
     * @param lazyInternalNetworkPenetrationMapping 内网穿透映射领域对象
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在
     * @author Jia wei Wu
     * @date 2023/12/29 05:21 下午
     **/

    @Override
    public Result<Boolean> exists(LazyInternalNetworkPenetrationMapping lazyInternalNetworkPenetrationMapping) {
        LazyInternalNetworkPenetrationMappingDO lazyInternalNetworkPenetrationMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkPenetrationMapping);
        Boolean exists = lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(lazyInternalNetworkPenetrationMappingDO));
        return ResultFactory.successOf(exists);
    }

}