package com.pangu.application.controller;

import com.pangu.base.domain.Grade;
import com.pangu.base.domain.PgClass;
import com.pangu.base.domain.Region;
import com.pangu.base.service.IGradeService;
import com.pangu.base.service.IPgClassService;
import com.pangu.base.service.IRegionService;
import com.pangu.common.core.controller.BaseController;
import com.pangu.common.core.domain.AjaxResult;
import com.pangu.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 开放API控制器
 * 供第三方应用调用，需通过 ApiAuthInterceptor 签名认证
 * @author pangu
 */
@RestController
@RequestMapping("/open")
public class OpenApiController extends BaseController {

    @Resource
    private IGradeService gradeService;
    @Resource
    private IPgClassService pgClassService;
    @Resource
    private IRegionService regionService;

    /**
     * 查询学生列表
     * 接口地址：GET /open/student/list
     * 参数：schoolId, gradeId, classId, pageNum, pageSize
     */
    @GetMapping("/student/list")
    public TableDataInfo studentList(Long schoolId, Long gradeId, Long classId) {
        startPage();
        // TODO: 学生模块未实现，暂返回空列表
        return getDataTable(List.of());
    }

    /**
     * 查询学校列表
     * 接口地址：GET /open/school/list
     * 参数：regionId, pageNum, pageSize
     */
    @GetMapping("/school/list")
    public TableDataInfo schoolList(Long regionId) {
        startPage();
        // TODO: 学校模块未实现，暂返回空列表
        return getDataTable(List.of());
    }

    /**
     * 查询年级列表
     * 接口地址：GET /open/grade/list
     */
    @GetMapping("/grade/list")
    public TableDataInfo gradeList() {
        startPage();
        Grade query = new Grade();
        query.setStatus("0");
        List<Grade> list = gradeService.selectGradeList(query);
        return getDataTable(list);
    }

    /**
     * 查询班级列表
     * 接口地址：GET /open/class/list
     */
    @GetMapping("/class/list")
    public TableDataInfo classList() {
        startPage();
        PgClass query = new PgClass();
        query.setStatus("0");
        List<PgClass> list = pgClassService.selectClassList(query);
        return getDataTable(list);
    }

    /**
     * 查询区域树
     * 接口地址：GET /open/region/tree
     */
    @GetMapping("/region/tree")
    public AjaxResult regionTree() {
        List<Region> tree = regionService.selectRegionTree();
        return success(tree);
    }

    /**
     * 查询会员列表
     * 接口地址：GET /open/member/list
     * 参数：phone, schoolId, pageNum, pageSize
     */
    @GetMapping("/member/list")
    public TableDataInfo memberList(String phone, Long schoolId) {
        startPage();
        // TODO: 会员模块未实现，暂返回空列表
        return getDataTable(List.of());
    }
}
