package com.hz.pm.api.expert.controller;


import com.hz.pm.api.expert.manage.ExpertAdminManage;
import com.hz.pm.api.expert.manage.ExpertManage;
import com.hz.pm.api.expert.model.ExpertLibraryReq;
import com.hz.pm.api.expert.model.req.AdminExpertBasicInfoModifyRequest;
import com.hz.pm.api.expert.model.req.ExpertRegistrationRequest;
import com.hz.pm.api.expert.model.req.ExpertUserBasicInfoSubmitRequest;
import com.hz.pm.api.expert.model.req.GetZzdInfoRequest;
import com.hz.pm.api.expert.model.vo.*;
import com.hz.pm.api.user.util.LoginUserUtil;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Liuxinxin
 * @since 2023-02-22
 */
@RestController
@Api(tags = "专家管理相关接口")
@RequestMapping(value = {"/api/v1/expert", "/expert"})
@RequiredArgsConstructor
public class ExpertController {

    private final ExpertManage expertManage;
    private final ExpertAdminManage expertAdminManage;

    @PostMapping("/registration")
    @ApiOperation("社会专家报名")
    @WebLog("社会专家报名")
    public void expertRegistration(@Valid @RequestBody ExpertRegistrationRequest request) {
        expertManage.expertRegistration(request);
    }

    @PostMapping("/basic-info-submit")
    @ApiOperation("专家管理员新增专家)")
    @WebLog("专家管理员新增专家")
    public void expertBasicInfoSubmit(@Valid @RequestBody ExpertUserBasicInfoSubmitRequest request) {
        expertManage.expertBasicInfoSubmit(request);
    }

    @PostMapping("/basic-info-submit-notvalid")
    @ApiOperation("专家管理员新增专家 参数不校检")
    @WebLog("专家管理员新增专家 参数不校检")
    public void expertBasicInfoSubmitNotValid(@RequestBody ExpertUserBasicInfoSubmitRequest request) {
        expertManage.expertBasicInfoSubmit(request);
    }

    @GetMapping("/portrait/{expertId}/{year}")
    public ExpertPortraitVO expertPortrait(@PathVariable Long expertId, @PathVariable Integer year) {
        return expertManage.expertPortrait(expertId, year);
    }

    @GetMapping("/detail")
    @ApiOperation("专家获取专家详细信息")
    public ExpertDetailVO getExpertDetail() {
        return expertManage.getExpertDetail(LoginUserUtil.getUserId(), true);
    }

    @GetMapping("/admin/detail")
    @ApiOperation("专家管理员获取专家详细信息")
    public ExpertDetailVO getExpertDetail(@RequestParam(value = "expertUserId") @NotNull Long userId) {
        return expertManage.getExpertDetail(userId, true);
    }

    @PostMapping("/expert-library/list")
    @ApiOperation("专家库列表查询接口")
    public PageVo<ExpertLibraryListItemVO> getExpertLibraryList(@RequestBody @Valid ExpertLibraryReq query) {
        return expertAdminManage.getExpertLibraryList(query);
    }

    @PostMapping("/basic-info-modify")
    @ApiOperation("专家信息编辑")
    @WebLog("专家信息编辑")
    public ExpertBasicInfoModifyResultVO expertBasicInfoModify(@Valid @RequestBody AdminExpertBasicInfoModifyRequest request) {
        return expertAdminManage.adminModifyExpertBasicInfo(request);
    }

    @PostMapping("/get-zzd-info")
    @ApiOperation("获取浙政钉用户信息")
    @WebLog("获取浙政钉用户信息")
    public ZzdInfoByMobileVO getZzdInfo(@Valid @RequestBody GetZzdInfoRequest request) {
        return expertAdminManage.getZzdInfo(request);
    }

}
