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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.smart.EduSmartWelcomeCampus;
import com.yida.data.common.core.entity.smart.EduSmartWelcomeDepartment;
import com.yida.data.common.core.entity.smart.EduSmartWelcomeGuide;
import com.yida.data.common.core.enums.EnableStatusEnum;
import com.yida.data.school.dto.smart.GuideFillInfoSaveDTO;
import com.yida.data.school.dto.smart.h5.CreateGuideStepOrderDTO;
import com.yida.data.school.smart.service.*;
import com.yida.data.school.vo.smart.h5.RosterStepPayInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 智慧迎新外部api(不鉴权)
 *
 * @author ZYJ
 * @date 2023-05-15 15:33:18
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "智慧迎新外部不鉴权api(学生端登录前接口)")
@RequestMapping("/out/eduSmartWelcomeGuide")
public class OutEduSmartWelcomeController {

    private final H5EduSmartWelcomeService h5EduSmartWelcomeService;
    private final EduSmartWelcomeGuideService eduSmartWelcomeGuideService;
    private final EduSmartWelcomeCampusService eduSmartWelcomeCampusService;
    private final EduSmartWelcomeDepartmentService eduSmartWelcomeDepartmentService;
    private final EduSmartWelcomeGuideRosterService eduSmartWelcomeGuideRosterService;

    @GetMapping("/getGuide")
    @ApiOperation("查询指南详情")
    ResultBean<EduSmartWelcomeGuide> getGuide(
        @RequestParam @ApiParam(value = "部门id", required = true) Long deptId,
        @RequestParam(required = false) @ApiParam(value = "校区id", required = true) Long campusId) {
        return ResultBean.buildSuccess(
            eduSmartWelcomeGuideService.getOne(Wrappers.lambdaQuery(new EduSmartWelcomeGuide())
                .eq(EduSmartWelcomeGuide::getDeptId, deptId)
                .eq(Objects.nonNull(campusId), EduSmartWelcomeGuide::getCampusId, campusId)
                .eq(EduSmartWelcomeGuide::getEnableStatus, EnableStatusEnum.ENABLE_STATUS.getStatus()))
        );
    }

    @PostMapping("/saveGuideFillInfo")
    @ApiOperation("保存填报信息")
    public ResultBean<String> saveGuideFillInfo(@RequestBody GuideFillInfoSaveDTO dto) {
        eduSmartWelcomeGuideRosterService.saveGuideFillInfo(dto);
        return ResultBean.buildSuccess();
    }

    @GetMapping("/getDepartmentTree")
    @ApiOperation("获取系部")
    public ResultBean<List<EduSmartWelcomeDepartment>> getDepartmentTree(@RequestParam Long deptId) {
        return ResultBean.buildSuccess(eduSmartWelcomeDepartmentService.getDepartmentTree(deptId));
    }

    @PostMapping("/createGuideStepOrder")
    @ApiOperation("生成迎新步骤订单")
    public ResultBean<RosterStepPayInfoVO> createGuideStepOrder(@RequestBody CreateGuideStepOrderDTO dto) {
        return ResultBean.buildSuccess(h5EduSmartWelcomeService.createGuideStepOrder(dto));
    }

    @GetMapping("/getCampusList")
    @ApiOperation("获取校区信息")
    public ResultBean<List<EduSmartWelcomeCampus>> getCampusList(@RequestParam Long deptId) {
        return ResultBean.buildSuccess(eduSmartWelcomeCampusService
            .list(Wrappers.<EduSmartWelcomeCampus>lambdaQuery().eq(EduSmartWelcomeCampus::getDeptId, deptId)));
    }
}
