package cn.cslg.report.service.business;

import cn.cslg.report.common.utils.Response;
import cn.cslg.report.entity.InvalidRecord;
import cn.cslg.report.entity.References;
import cn.cslg.report.entity.ReviewHistory;
import cn.cslg.report.mapper.InvalidRecordMapper;
import cn.cslg.report.mapper.ReferencesMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class ReferencesService extends ServiceImpl<ReferencesMapper, References> {
    public final InvalidRecordMapper invalidRecordMapper;

    public String deleteReferences(int id) throws IOException {
        this.removeById(id);
        return Response.success();
    }

    public String updateReferences(References references) throws IOException {
        references.updateById();
        return Response.success();
    }

    public String addReferences(References references) throws IOException {
        references.insert();
        return Response.success();
    }

    public String queryReferences(References references){
        LambdaQueryWrapper<References> wrapper =new LambdaQueryWrapper<>();
        wrapper.eq(References::getPatentNo,references.getPatentNo());
        if (references.getSize() != null && references.getSize() != null) {
            IPage<References> pages = this.page(new Page<>(references.getCurrent(), references.getSize()), wrapper);
            return Response.success(pages);
        } else {
            List<References> referencesList= this.list(wrapper);
            return Response.success(referencesList);
        }
    }


}