package com.corewing.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.corewing.app.dto.publicFirmware.PublicBoardTypeListRequest;
import com.corewing.app.dto.publicFirmware.PublicFirmwareListRequest;
import com.corewing.app.entity.AppPublicFirmwarePlane;
import com.corewing.app.mapper.AppPublicFirmwarePlaneMapper;
import com.corewing.app.service.AppPublicFirmwarePlaneService;
import org.springframework.stereotype.Service;

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

@Service
public class AppPublicFirmwarePlaneServiceImpl extends ServiceImpl<AppPublicFirmwarePlaneMapper, AppPublicFirmwarePlane> implements AppPublicFirmwarePlaneService {
    @Override
    public List<String> getBoardTypeList(PublicBoardTypeListRequest publicBoardTypeListRequest) {
        LambdaQueryWrapper<AppPublicFirmwarePlane> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AppPublicFirmwarePlane::getType, publicBoardTypeListRequest.getFirmwareType());
        queryWrapper.eq(AppPublicFirmwarePlane::getVersionId, publicBoardTypeListRequest.getVersionId());
        return list(queryWrapper).stream().map(AppPublicFirmwarePlane::getBoardType).filter(Objects::nonNull).collect(Collectors.toList());
    }

    @Override
    public List<AppPublicFirmwarePlane> getFirmwareList(PublicFirmwareListRequest publicFirmwareListRequest) {
        LambdaQueryWrapper<AppPublicFirmwarePlane> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AppPublicFirmwarePlane::getType, publicFirmwareListRequest.getFirmwareType());
        queryWrapper.eq(AppPublicFirmwarePlane::getVersionId, publicFirmwareListRequest.getVersionId());
        queryWrapper.eq(AppPublicFirmwarePlane::getBoardType, publicFirmwareListRequest.getBoardType());
        return list(queryWrapper);
    }
}
