package com.hzs.system.config.provider;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.vertex.BdVertex;

import com.hzs.common.domain.vertex.ext.BdVertexExt;
import com.hzs.system.config.IVertexServiceApi;
import com.hzs.system.config.dto.VertexDTO;
import com.hzs.system.config.service.IBdVertexService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class IVertexServiceProvider implements IVertexServiceApi {

    @Autowired
    private IBdVertexService vertexService;

    @Override
    public R<List<VertexDTO>> findAll() {
        List<BdVertex> list = vertexService.list();
        List<VertexDTO> resultList = new ArrayList<>();
        for (BdVertex bdVertex : list) {
            VertexDTO vertexDTO = BeanUtil.copyProperties(bdVertex, VertexDTO.class);
            resultList.add(vertexDTO);
        }
        return R.ok(resultList);
    }

    @Override
    public R<List<VertexDTO>> findAllByPkCountry(Integer pkCountry) {
        LambdaQueryWrapper<BdVertex> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BdVertex::getPkCountry, pkCountry);
        List<BdVertex> list = vertexService.list(queryWrapper);
        List<VertexDTO> resultList = new ArrayList<>();
        for (BdVertex bdVertex : list) {
            VertexDTO vertexDTO = BeanUtil.copyProperties(bdVertex, VertexDTO.class);
            resultList.add(vertexDTO);
        }
        return R.ok(resultList);
    }

    @Override
    public R<VertexDTO> findById(Long pkVertex) {
        BdVertexExt bdVertex = vertexService.queryVertexAndMember(pkVertex);
        if (null != bdVertex) {
            VertexDTO vertexDTO = BeanUtil.copyProperties(bdVertex, VertexDTO.class);
            return R.ok(vertexDTO);
        }
        return R.fail();
    }

}
