package com.muyu.enterprise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.muyu.domain.MessageTemplate;
import com.muyu.domain.resp.WarnStrategyAndVinResp;
import com.muyu.enterprise.mapper.WarnStrategyMapper;
import com.muyu.enterprise.service.WarnStrategyService;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.domain.VehicleType;
import com.muyu.domain.WarnStrategy;
import com.muyu.domain.req.WarnVehicleReq;
import com.muyu.domain.resp.WarnVehicleResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class WarnStrategyServiceImpl extends ServiceImpl<WarnStrategyMapper, WarnStrategy>
        implements WarnStrategyService {

    @Autowired
    private WarnStrategyMapper warnStrategyMapper;


    @Override
    public List<WarnVehicleResp> selectList(WarnVehicleReq req) {
        MPJLambdaWrapper<WarnStrategy> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAll(WarnStrategy.class)
                .selectAs(VehicleType::getVehicleTypeName,WarnVehicleResp::getVehicleTypeName)
                .selectAs(MessageTemplate::getMessageTemplateName,WarnVehicleResp::getMessageTemplateName)
                .leftJoin(VehicleType.class,  VehicleType::getVehicleTypeId,WarnStrategy::getVehicleTypeId)
                .leftJoin(MessageTemplate.class, MessageTemplate::getMessageTemplateId,WarnStrategy::getMessageTemplateId)
                .like(
                        StringUtils.isNotEmpty(req.getStrategyName()),
                        WarnStrategy::getStrategyName,req.getStrategyName()
                );
        List<WarnVehicleResp> list = warnStrategyMapper.selectJoinList(WarnVehicleResp.class, wrapper);
        return list;
    }

    @Override
    public List<WarnStrategyAndVinResp> findById(Long vehicleId) {
        List<WarnStrategyAndVinResp> byId = warnStrategyMapper.findById(vehicleId);
        if (byId == null) {
            return null;
        }
        return byId;
    }

}
