package com.ywt.service;

import com.ywt.core.BaseResponse;
import com.ywt.core.DataResponse;
import com.ywt.core.utils.Checker;
import com.ywt.domain.entity.glasses.Shop;
import com.ywt.domain.entity.glasses.ShopRepository;

import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@DubboService
@Service
public class ShopService extends ServiceBase {

    private static final Logger logger = LoggerFactory.getLogger(ShopService.class);

    @Autowired
    private ShopRepository shopRepository;


    public BaseResponse getShopList() {
        DataResponse<Object> response = new DataResponse<>();
        List<Object> returnList = new ArrayList<>();
        List<Shop> all = shopRepository.findAll();
        all = all.stream().filter(p -> p.getDeleted() == 0).collect(Collectors.toList());
        if (!Checker.isNone(all)) {
            for (Shop shop : all) {
                HashMap<String, Object> map = new HashMap<>();
                map.put("id", shop.getId());
                map.put("name", shop.getName());
                returnList.add(map);
            }
        }
        response.setData(returnList);
        return response.succeed();
    }
}
