package com.seer.teach.teacher.service.registry.smartRead.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.enums.teacher.SmartReadEnum;
import com.seer.teach.common.utils.PageConverterUtils;
import com.seer.teach.teacher.common.req.BookPageReq;
import com.seer.teach.teacher.common.resp.AppBookInfoResp;
import com.seer.teach.teacher.convert.TreasuryBoxConvert;
import com.seer.teach.teacher.module.entity.TreasuryBoxArticlesEntity;
import com.seer.teach.teacher.service.ReadBookService;
import com.seer.teach.teacher.service.registry.smartRead.SmartReadHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 编程类读物处理器实现类
 * 用于处理编程相关的智能阅读书籍查询逻辑
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ProgrammingHandlerImpl implements SmartReadHandler {

    private final ReadBookService readBookService;

    /**
     * 获取处理器类型
     * @return 返回编程类读物对应的类型标识
     */
    @Override
    public Integer getType() {
        return SmartReadEnum.PROGRAMMING.getType();
    }

    /**
     * 获取编程类书籍列表
     * @param userId 用户ID
     * @param param 书籍分页查询参数，包含页码和每页数量等信息
     * @return 返回编程类书籍的分页列表数据
     */
    @Override
    public PageListBean<AppBookInfoResp> getBookList(Integer userId, BookPageReq param) {
        // 构建分页对象
        IPage<TreasuryBoxArticlesEntity> page = new Page<>(param.getPage(), param.getLimits());
        IPage<TreasuryBoxArticlesEntity> booksPage = readBookService.programming(page);
        return PageConverterUtils.convertPageListBean(booksPage, TreasuryBoxConvert.INSTANCE::toBookInfoList);
    }

}

