package com.yuchen.saas.park.service.service.property;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuchen.saas.park.api.entity.property.PropertyDepositHouse;
import com.yuchen.saas.park.api.vo.property.PropertyDepositHouseGroupListVo;
import com.yuchen.saas.park.api.vo.property.PropertyDepositHouseListVo;
import com.yuchen.saas.park.service.mapper.property.PropertyDepositHouseMapper;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.stereotype.Service;

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

/**
 * 押金绑定房源
 */
@Service
public class PropertyDepositHouseService extends ServiceImpl<PropertyDepositHouseMapper, PropertyDepositHouse> {


    public List<PropertyDepositHouseGroupListVo> listDepositHouseGroupVo(List<Long> depositIdList) {
        if (Func.isEmpty(depositIdList)) {
            return new ArrayList<>();
        }
        return this.baseMapper.listDepositHouseGroup(this.getDepositIds(depositIdList));
    }

    public List<PropertyDepositHouseListVo> listDepositHouseVo(List<Long> depositIdList) {
        if (Func.isEmpty(depositIdList)) {
            return new ArrayList<>();
        }
        return this.baseMapper.listDepositHouse(this.getDepositIds(depositIdList));
    }


    private String getDepositIds(List<Long> depositIdList) {
        List<String> depositIds = new ArrayList<>();
        depositIdList.forEach(item -> {
            depositIds.add(item.toString());
        });
        return String.join(",",depositIds);
    }

    public List<PropertyDepositHouse> listByHouseId(long houseId) {
        LambdaQueryWrapper<PropertyDepositHouse> qw = new LambdaQueryWrapper<>();
        qw.eq(PropertyDepositHouse::getHouseId,houseId);
        return this.list(qw);
    }

    public List<Long> listDepositIdByHouseId(long houseId) {
        return this.listByHouseId(houseId).stream().map(PropertyDepositHouse::getDepositId).collect(Collectors.toList());
    }

    public List<Long> listHouseId(long depositId) {
        List<PropertyDepositHouse> res = this.lambdaQuery().eq(PropertyDepositHouse::getDepositId,depositId).list();
        return res.stream().map(PropertyDepositHouse::getHouseId).collect(Collectors.toList());
    }


}
