package com.yida.data.school.index.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.school.EduDeptHomeApp;
import com.yida.data.common.core.entity.school.EduSchoolHomeMicroPic;
import com.yida.data.school.index.service.EduDeptHomeAppService;
import com.yida.data.school.index.service.EduSchoolHomeCoverService;
import com.yida.data.school.index.service.EduSchoolHomeMicroIndexService;
import com.yida.data.school.index.service.EduSchoolHomeMicroPicService;
import com.yida.data.school.vo.index.HomeInfoVO;
import com.yida.data.school.vo.index.SchoolIndexVO;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;

@Api(tags = "校园主页（不鉴权）")
@RequestMapping("/in/index/home")
@RestController
@RequiredArgsConstructor
public class InEduSchoolHomeController {

    private final EduSchoolHomeMicroIndexService eduSchoolHomeMicroIndexService;
    private final EduSchoolHomeMicroPicService eduSchoolHomeMicroPicService;
    private final EduSchoolHomeCoverService eduSchoolHomeCoverService;
    private final EduDeptHomeAppService eduDeptHomeAppService;


    @ApiOperation("查询校园概况")
    @GetMapping("/getMicroSchoolIndex")
    public ResultBean<SchoolIndexVO> getMicroSchoolIndex(@ApiParam("栏目id") @RequestParam(required = false) Long colId) {
        if (colId != null) {
            return ResultBean.buildSuccess(eduSchoolHomeMicroIndexService.getInfo(colId));
        }
        return ResultBean.buildSuccess();
    }

    @ApiOperation("根据栏目id查询图片")
    @GetMapping("/listPicByCol")
    public ResultBean<List<EduSchoolHomeMicroPic>> listPicByCol(@ApiParam("栏目id") Long colId) {
        return ResultBean.buildSuccess(eduSchoolHomeMicroPicService.list(Wrappers.lambdaQuery(new EduSchoolHomeMicroPic())
            .eq(EduSchoolHomeMicroPic::getColId, colId)
            .orderByAsc(EduSchoolHomeMicroPic::getSort)));
    }

    @ApiOperation("主页信息查询")
    @GetMapping("/getHomeInfo")
    public ResultBean<HomeInfoVO> getHomeInfo(@ApiParam("学校id") Long schoolId, @RequestParam(required = false) Integer userType) {
        return ResultBean.buildSuccess(eduSchoolHomeCoverService.getHomeInfo(schoolId, userType));
    }

    @ApiOperation("主页信息查询")
    @GetMapping("/getDeptAppList")
    public ResultBean<List<EduDeptHomeApp>> getDeptAppList(@RequestParam("schoolId") Long schoolId) {
        return ResultBean.buildSuccess(eduDeptHomeAppService.list(Wrappers.lambdaQuery(new EduDeptHomeApp())
            .eq(EduDeptHomeApp::getDeptId, schoolId)));
    }
}
