package com.seer.teach.admin.service.impl;

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.seer.teach.admin.convert.QuestionGenerationLogConvert;
import com.seer.teach.admin.request.QuestionGenerationLogQueryReq;
import com.seer.teach.admin.response.QuestionGenerationLogResp;
import com.seer.teach.admin.service.AdminQuestionGenerationLogService;
import com.seer.teach.teacher.module.entity.QuestionGenerationLogEntity;
import com.seer.teach.teacher.service.QuestionGenerationLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * <p>
 * 管理端题目生成日志服务实现类
 * </p>
 *
 * @author Lingma
 * @since 2025-11-21
 */
@Service
@RequiredArgsConstructor
public class AdminQuestionGenerationLogServiceImpl implements AdminQuestionGenerationLogService {

    private final QuestionGenerationLogService questionGenerationLogService;

    /**
     * 分页查询题目生成日志
     *
     * @param req 查询条件
     * @return 题目生成日志分页数据
     */
    @Override
    public IPage<QuestionGenerationLogResp> pageQuestionGenerationLogs(QuestionGenerationLogQueryReq req) {
        Page<QuestionGenerationLogEntity> page = new Page<>(req.getPageNo(), req.getPageSize());
        IPage<QuestionGenerationLogEntity> entityPage = questionGenerationLogService.page(page,
                new LambdaQueryWrapper<>(QuestionGenerationLogEntity.class)
                        .eq(Objects.nonNull(req.getKnowId()),QuestionGenerationLogEntity::getKnowId, req.getKnowId())
                        .like(StringUtils.hasText(req.getKnowledgePointName()),QuestionGenerationLogEntity::getKnowledgePointName,req.getKnowledgePointName()));
        return entityPage.convert(QuestionGenerationLogConvert.INSTANCE::convert);
    }
}