package com.yida.data.user.controller.app;

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.common.ResultMsgType;
import com.yida.data.user.dto.CheckStudentInformationDTO;
import com.yida.data.user.dto.SaveParentInformationDTO;
import com.yida.data.user.service.EduSchoolParentInformationService;
import com.yida.data.user.service.EduSchoolStudentInformationService;
import com.yida.data.user.service.EduSchoolTipsService;
import com.yida.data.user.vo.CheckStudentInformationReturnVO;
import com.yida.data.user.vo.SchoolTipsVo;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
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 javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 学校智慧迎新app接口
 *
 * @author ZYJ
 * @date 2021/8/19
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/in/welcome")
@Api(tags = "学校智慧迎新app接口")
public class AppEduSchoolWelcomeController {

    private final EduSchoolTipsService eduSchoolTipsService;

    private final EduSchoolStudentInformationService eduSchoolStudentInformationService;

    private final EduSchoolParentInformationService eduSchoolParentInformationService;

    /**
     * 根据学校id获取须知信息
     *
     * @param schoolId 学校id
     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.school.vo.SchoolTipsVo>
     * @author ZYJ
     * @date 2021/8/19 17:46
     */
    @ApiOperation("获取学校须知信息")
    @PostMapping("/getSchoolTips")
    public ResultBean<SchoolTipsVo> getSchoolTips(
            @ApiParam(value = "学校id", required = true) @RequestParam Long schoolId) {
        try {
            return ResultBean.buildSuccess(eduSchoolTipsService.getSchoolTips(schoolId));
        } catch (Exception e) {
            log.error("获取学校须知信息失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 验证提交的学生信息
     *
     * @param checkStudentInformationDTO 验证学生信息请求类
     * @return com.yida.data.common.core.common.ResultBean<java.util.List < com.yida.data.school.vo.CheckStudentInformationReturnVO>>
     * @author ZYJ
     * @date 2021/8/19 20:14
     */
    @ApiOperation("验证提交的学生信息")
    @PostMapping("/checkStudentInformation")
    public ResultBean<List<CheckStudentInformationReturnVO>> checkStudentInformation(
            @Valid @RequestBody CheckStudentInformationDTO checkStudentInformationDTO) {
        try {
            return eduSchoolStudentInformationService.checkStudentInformation(checkStudentInformationDTO);
        } catch (Exception e) {
            log.error("验证提交的学生信息失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.CHECK_FAIL.getValue());
        }
    }

    /**
     * 保存家长提交信息
     *
     * @param saveParentInformationDTO 家长提交信息
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/8/19 20:58
     */
    @ApiOperation("保存家长提交信息")
    @PostMapping("/saveParentInformation")
    public ResultBean<String> saveParentInformation(
            @Valid @RequestBody SaveParentInformationDTO saveParentInformationDTO) {
        try {
            return eduSchoolParentInformationService.saveParentInformation(saveParentInformationDTO);
        } catch (Exception e) {
            log.error("保存家长提交信息失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.SERVER_ERROR.getValue());
        }
    }
}
