package com.ruoyi.web.modules.news.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.modules.news.domain.AgriculturalCourseListVo;
import com.ruoyi.web.modules.news.domain.AgriculturalCourseQuery;
import com.ruoyi.web.modules.news.service.IAgriculturalCourseService;
import com.ruoyi.web.modules.news.support.AgriculturalCoursePageSupport;
import com.ruoyi.web.modules.news.support.AgriculturalCourseQuerySupport;
import com.ruoyi.web.modules.news.support.AgriculturalCourseTypeValidator;

/**
 * 移动端农技课堂（v_agricultural_course，按 type 筛选）。
 */
@RestController
@RequestMapping("/app/agriculturalCourse")
public class BizAppAgriculturalCourseController extends BaseController
{
    @Autowired
    private IAgriculturalCourseService agriculturalCourseService;

    @Autowired
    private AgriculturalCourseTypeValidator agriculturalCourseTypeValidator;

    /**
     * 按 type 分页查询已发布农技课堂列表，支持 title 关键字模糊搜索。
     *
     * @param query type 必填（视频主题 005001–005004 或培训状态 006001–006004）；title 可选
     */
    @GetMapping("/list")
    public TableDataInfo list(AgriculturalCourseQuery query)
    {
        AgriculturalCourseQuery effective = AgriculturalCourseQuerySupport.normalize(query);
        agriculturalCourseTypeValidator.assertAllowed(effective.getType());
        AgriculturalCoursePageSupport.startPage(effective);
        List<AgriculturalCourseListVo> list = agriculturalCourseService.selectAgriculturalCourseList(effective);
        return getDataTable(list);
    }
}
