package com.bonus.canteen.core.customer.api;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.bonus.canteen.core.customer.mapper.CustPlaceMapper;
import com.bonus.canteen.core.customer.model.CustPlace;
import com.bonus.canteen.core.customer.vo.CustPlaceListDutyAreaVO;
import com.bonus.common.houqin.constant.LeConstants;
import com.bonus.common.houqin.utils.id.Id;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.lang.invoke.SerializedLambda;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CustPlaceApi {
   @Autowired
   @Lazy
   private CustPlaceMapper custPlaceMapper;

   public void initCustPlace(String merchantName) {
      CustPlace custPlace = new CustPlace();
      custPlace.setPlaceId(Id.next());
      String merchantDefault = merchantName + "(默认)";
      custPlace.setPlaceName(merchantDefault);
      custPlace.setPlaceFullName(merchantDefault);
      custPlace.setSuperIds(LeConstants.DATA_DEFAULT_LONG.toString());
      this.custPlaceMapper.insert(custPlace);
   }
//
//   public List<Long> queryCustPlaceBySuperId(Long superId) {
//      return this.custPlaceMapper.queryCustPlaceBySuperId(superId);
//   }
//
//   public CustPlace getOneByPlaceId(Long placeId) {
//      return (CustPlace)this.custPlaceMapper.selectOne((Wrapper)Wrappers.lambdaQuery(CustPlace.class).eq(CustPlace::getPlaceId, placeId));
//   }
//
//   public String getPlaceUserNameByPlaceId(Long placeId) {
//      return this.custPlaceMapper.getPlaceUserNameByPlaceId(placeId);
//   }
//
//   public List<CustPlaceListDutyAreaVO> listPlaceFullNameByIds(List<Long> placeIds) {
//      return this.custPlaceMapper.queryDutyAreaByPlaceIds(placeIds);
//   }

   public List<Long> listPlaceIdByUserIds(List<Long> userIds) {
      return this.custPlaceMapper.selectList(Wrappers.lambdaQuery(CustPlace.class).select(CustPlace::getPlaceId)
              .in(CustPlace::getUserId, userIds)).stream().map(CustPlace::getPlaceId).collect(Collectors.toList());
   }
}
