package com.yida.data.system.controller;

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.common.ResultMsgType;
import com.yida.data.system.dto.AgentSchoolRelateSaveDTO;
import com.yida.data.system.service.EduAgentSchoolRelateService;
import com.yida.data.system.service.EduAgentService;
import com.yida.data.system.vo.AgentSchoolRelateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 管理员维护代理商 Controller
 *
 * @author ZYJ
 * @date 2021-09-26 11:19:45
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/eduAgentManagement")
@Api(tags = "代理商管理后台接口")
@PreAuthorize("hasRole('role:admin')")
public class EduAgentManagementController {

    private final EduAgentService eduAgentService;

    private final EduAgentSchoolRelateService eduAgentSchoolRelateService;

//    /**
//     * 查询代理商列表数据
//     *
//     * @param agentSelectPageDTO 代理商后台列表请求类
//     * @return com.yida.data.common.core.common.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < com.yida.data.system.vo.AgentSelectPageVO>>
//     * @author ZYJ
//     * @date 2021/9/26 11:40
//     */
//    @PostMapping(value = "/listAgentPage")
//    @ApiOperation(value = "查询代理商列表数据", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
//    public ResultBean<IPage<AgentSelectPageVO>> listAtlasPage(@Valid AgentSelectPageDTO agentSelectPageDTO) {
//        try {
//            return this.eduAgentService.listAgentPage(agentSelectPageDTO);
//        } catch (Exception e) {
//            log.error("查询代理商列表数据失败: {}", e.getMessage(), e);
//            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
//        }
//    }
//
//    /**
//     * 保存代理商数据
//     *
//     * @param agentSaveDTO 保存代理商请求类
//     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
//     * @author ZYJ
//     * @date 2021/9/26 13:48
//     */
//    @PostMapping(value = "/saveAgent", consumes = MediaType.APPLICATION_JSON_VALUE)
//    @ApiOperation(value = "保存代理商数据", consumes = MediaType.APPLICATION_JSON_VALUE)
//    public ResultBean<String> saveAgent(@Valid @RequestBody AgentSaveDTO agentSaveDTO) {
//        try {
//            return this.eduAgentService.saveAgent(agentSaveDTO);
//        } catch (Exception e) {
//            log.error("保存代理商数据失败: {}", e.getMessage(), e);
//            return ResultBean.buildError(ResultMsgType.SAVE_FAIL.getValue());
//        }
//    }

//    /**
//     * 获取代理商详情
//     *
//     * @param agentId 代理商id
//     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.system.vo.AgentDetailVO>
//     * @author ZYJ
//     * @date 2021/9/26 14:59
//     */
//    @ApiOperation("获取代理商详情")
//    @GetMapping(value = "/getAgentInfo")
//    public ResultBean<AgentDetailVO> getAgentInfo(
//            @ApiParam(value = "代理商id", required = true) @RequestParam Long agentId) {
//        try {
//            return this.eduAgentService.getAgentInfo(agentId);
//        } catch (Exception e) {
//            log.error("获取代理商详情失败: {}", e.getMessage(), e);
//            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
//        }
//    }

    @ApiOperation("查询代理商和学校关联关系")
    @GetMapping(value = "/listAgentSchoolRelates")
    public ResultBean<List<AgentSchoolRelateVO>> listAgentSchoolRelates( ) {
        return ResultBean.buildSuccess(this.eduAgentSchoolRelateService.listAgentSchoolRelates());
    }

    /**
     * 保存代理商和学校关联关系
     *
     * @param agentSchoolRelateSaveDTO 需要保存的关联关系集合数据
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/9/26 16:58
     */
    @ApiOperation(value = "保存代理商和学校关联关系", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveAgentSchoolRelate", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> saveAgentSchoolRelate(@Valid @RequestBody AgentSchoolRelateSaveDTO agentSchoolRelateSaveDTO) {
        try {
            return this.eduAgentSchoolRelateService.saveAgentSchoolRelate(agentSchoolRelateSaveDTO);
        } catch (Exception e) {
            log.error("保存代理商和学校关联关系失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.SAVE_FAIL.getValue());
        }
    }

//    /**
//     * 获取代理商管理员账号详情
//     *
//     * @param agentId 代理商id
//     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.system.vo.AgentAdminAccountDetailVO>
//     * @author ZYJ
//     * @date 2021/9/29 16:02
//     */
//    @ApiOperation("获取代理商管理员账号详情")
//    @GetMapping(value = "/getAgentAdminAccountInfo")
//    public ResultBean<AgentAdminAccountDetailVO> getAgentAdminAccountInfo(
//            @ApiParam(value = "代理商id", required = true) @RequestParam Long agentId) {
//        try {
//            return this.eduAgentService.getAgentAdminAccountInfo(agentId);
//        } catch (Exception e) {
//            log.error("获取代理商管理员账号详情失败: {}", e.getMessage(), e);
//            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
//        }
//    }
//
//    /**
//     * 创建代理商管理员账号
//     *
//     * @param agentAdminAccountSaveDTO 保存代理商管理员账号请求类
//     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
//     * @author ZYJ
//     * @date 2021/9/28 16:24
//     */
//    @PostMapping(value = "/saveAgentAdminAccount", consumes = MediaType.APPLICATION_JSON_VALUE)
//    @ApiOperation(value = "保存代理商管理员账号", consumes = MediaType.APPLICATION_JSON_VALUE)
//    public ResultBean<String> saveAgentAdminAccount(
//            @Valid @RequestBody AgentAdminAccountSaveDTO agentAdminAccountSaveDTO) {
//        return this.eduAgentService.saveAgentAdminAccount(agentAdminAccountSaveDTO);
//    }
}
