package cn.sh.stc.sict.theme.hphy.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;

import cn.sh.stc.sict.theme.hphy.dao.HphyGuideQuestionOptionMapper;
import cn.sh.stc.sict.theme.hphy.model.HphyGuideQuestionOption;
import cn.sh.stc.sict.theme.hphy.service.HphyGuideQuestionOptionService;

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


@Service("hphyGuideQuestionOptionService")
@AllArgsConstructor
public class HphyGuideQuestionOptionServiceImpl extends ServiceImpl<HphyGuideQuestionOptionMapper, HphyGuideQuestionOption> implements HphyGuideQuestionOptionService {

    private final HphyGuideQuestionOptionMapper hphyGuideQuestionOptionMapper;

    /**
     * 获取用户吃药状态
     *
     * @param guideQuestionId
     * @return
     */
    @Override
    public HphyGuideQuestionOption getDrugOption(Long guideQuestionId) {
        LambdaQueryWrapper<HphyGuideQuestionOption> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HphyGuideQuestionOption::getGuideQuestionId, guideQuestionId)
                .last("limit 1");
        return this.getOne(wrapper);
    }

    /**
     * 删除历史数据
     *
     * @param guideQuestionId
     * @return
     */
    @Override
    public boolean deleteByQuestionId(Long guideQuestionId) {
        LambdaQueryWrapper<HphyGuideQuestionOption> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HphyGuideQuestionOption::getGuideQuestionId, guideQuestionId);
        return this.remove(wrapper);
    }

    @Override
    public List<HphyGuideQuestionOption> listByGqId(List<Long> idList) {
        if (CollUtil.isNotEmpty(idList)) {
            return this.list(new LambdaQueryWrapper<HphyGuideQuestionOption>().in(HphyGuideQuestionOption::getGuideQuestionId, idList));
        }
        return new ArrayList<>();
    }
}
