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

import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.server.permeate.client.mapping.LazyInternalNetworkServerPermeateClientMapping;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.server.permeate.client.mapping.LazyInternalNetworkServerPermeateClientMappingRepository;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.entity.LazyInternalNetworkServerPermeateClientMappingDO;
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 LazyInternalNetworkServerPermeateClientMappingRepositoryImpl implements LazyInternalNetworkServerPermeateClientMappingRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

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

    @Override
    public Result<LazyInternalNetworkServerPermeateClientMapping> story(LazyInternalNetworkServerPermeateClientMapping lazyInternalNetworkServerPermeateClientMapping) {
        LazyInternalNetworkServerPermeateClientMappingDO lazyInternalNetworkServerPermeateClientMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkServerPermeateClientMapping);
        lazyInternalNetworkServerPermeateClientMappingDO.setIsDeleted(false);
        lazyLambdaStream.upsertRemoveNull(lazyInternalNetworkServerPermeateClientMappingDO);
        return ResultFactory.successOf();
    }

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

    @Override
    public Result<List<LazyInternalNetworkServerPermeateClientMapping>> batchStory(List<LazyInternalNetworkServerPermeateClientMapping> lazyInternalNetworkServerPermeateClientMappingList) {
        List<LazyInternalNetworkServerPermeateClientMappingDO> lazyInternalNetworkServerPermeateClientMappingDOList = lazyInternalNetworkServerPermeateClientMappingList.stream().map(LazyInternalNetworkPenetrationMappingConverter.INSTANCE::fromInternalNetworkPenetrationMapping).collect(Collectors.toList());
        lazyLambdaStream.upsert(lazyInternalNetworkServerPermeateClientMappingDOList);
        return ResultFactory.successOf();
    }

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

    @Override
    public Result<LazyInternalNetworkServerPermeateClientMapping> findOne(LazyInternalNetworkServerPermeateClientMapping lazyInternalNetworkServerPermeateClientMapping) {
        LazyInternalNetworkServerPermeateClientMappingDO lazyInternalNetworkServerPermeateClientMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkServerPermeateClientMapping);
        LazyInternalNetworkServerPermeateClientMapping lazyInternalNetworkServerPermeateClientMappingOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(lazyInternalNetworkServerPermeateClientMappingDO), LazyInternalNetworkServerPermeateClientMapping.class);
        return ResultFactory.successOf(lazyInternalNetworkServerPermeateClientMappingOne);
    }

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

    @Override
    public Result<List<LazyInternalNetworkServerPermeateClientMapping>> findList(LazyInternalNetworkServerPermeateClientMapping lazyInternalNetworkServerPermeateClientMapping) {
        LazyInternalNetworkServerPermeateClientMappingDO lazyInternalNetworkServerPermeateClientMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkServerPermeateClientMapping);
        List<LazyInternalNetworkServerPermeateClientMapping> lazyInternalNetworkServerPermeateClientMappingList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(lazyInternalNetworkServerPermeateClientMappingDO), LazyInternalNetworkServerPermeateClientMapping.class);
        return ResultFactory.successOf(lazyInternalNetworkServerPermeateClientMappingList);
    }

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

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

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

    @Override
    public Result<LazyInternalNetworkServerPermeateClientMapping> remove(LazyInternalNetworkServerPermeateClientMapping lazyInternalNetworkServerPermeateClientMapping) {
        LazyInternalNetworkServerPermeateClientMappingDO lazyInternalNetworkServerPermeateClientMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkServerPermeateClientMapping);
        lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(lazyInternalNetworkServerPermeateClientMappingDO));
        return ResultFactory.successOf();
    }

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

    @Override
    public Result<Boolean> exists(LazyInternalNetworkServerPermeateClientMapping lazyInternalNetworkServerPermeateClientMapping) {
        LazyInternalNetworkServerPermeateClientMappingDO lazyInternalNetworkServerPermeateClientMappingDO = LazyInternalNetworkPenetrationMappingConverter.INSTANCE.fromInternalNetworkPenetrationMapping(lazyInternalNetworkServerPermeateClientMapping);
        Boolean exists = lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(lazyInternalNetworkServerPermeateClientMappingDO));
        return ResultFactory.successOf(exists);
    }

}