package com.usky.sas.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.sas.service.SasPersonnelService;
import com.usky.sas.service.vo.PersonnelDetailResponse;
import com.usky.sas.service.vo.PersonnelListItem;
import com.usky.sas.service.vo.PersonnelPageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 人员管理接口
 *
 * 对应 API 文档：
 * /prod-api/service-sas/personnel/...
 */
@RestController
@RequestMapping("/personnel")
public class SasPersonnelController {

    @Autowired
    private SasPersonnelService sasPersonnelService;

    /**
     * 1.1 查询白名单人员信息
     */
    @GetMapping("/whitelist")
    public ApiResult<CommonPage<PersonnelListItem>> whitelist(PersonnelPageRequest request) {
        return ApiResult.success(sasPersonnelService.whitelistPage(request));
    }

    /**
     * 1.2 同步白名单
     */
    @PostMapping("/whitelistSync")
    public ApiResult<Integer> whitelistSync() {
        return ApiResult.success(sasPersonnelService.syncWhitelist());
    }

    /**
     * 1.3 查询白名单人员详情
     */
    @GetMapping("/whitelist/{personCode}")
    public ApiResult<PersonnelDetailResponse> whitelistDetail(@PathVariable("personCode") String personCode) {
        return ApiResult.success(sasPersonnelService.whitelistDetail(personCode));
    }

    /**
     * 2.1 查询黑名单人员信息
     */
    @GetMapping("/blacklist")
    public ApiResult<CommonPage<PersonnelListItem>> blacklist(PersonnelPageRequest request) {
        return ApiResult.success(sasPersonnelService.blacklistPage(request));
    }

    /**
     * 2.2 同步黑名单
     */
    @PostMapping("/blacklistSync")
    public ApiResult<Integer> blacklistSync() {
        return ApiResult.success(sasPersonnelService.syncBlacklist());
    }

    /**
     * 2.3 查询黑名单人员详情
     */
    @GetMapping("/blacklist/{personCode}")
    public ApiResult<PersonnelDetailResponse> blacklistDetail(@PathVariable("personCode") String personCode) {
        return ApiResult.success(sasPersonnelService.blacklistDetail(personCode));
    }

    /**
     * 3.1 查询在册人员信息
     */
    @GetMapping("/registered")
    public ApiResult<CommonPage<PersonnelListItem>> registered(PersonnelPageRequest request) {
        return ApiResult.success(sasPersonnelService.registeredPage(request));
    }

    /**
     * 3.2 同步在册人员
     */
    @PostMapping("/registeredSync")
    public ApiResult<Integer> registeredSync() {
        return ApiResult.success(sasPersonnelService.syncRegistered());
    }

    /**
     * 3.3 查询在册人员详情
     */
    @GetMapping("/registered/{personCode}")
    public ApiResult<PersonnelDetailResponse> registeredDetail(@PathVariable("personCode") String personCode) {
        return ApiResult.success(sasPersonnelService.registeredDetail(personCode));
    }

    /**
     * 4.1 查询关注人员信息
     */
    @GetMapping("/follow")
    public ApiResult<CommonPage<PersonnelListItem>> follow(PersonnelPageRequest request) {
        return ApiResult.success(sasPersonnelService.followPage(request));
    }

    /**
     * 4.2 同步关注人员
     */
    @PostMapping("/followSync")
    public ApiResult<Integer> followSync() {
        return ApiResult.success(sasPersonnelService.syncFollow());
    }

    /**
     * 4.3 查询关注人员详情
     */
    @GetMapping("/follow/{personCode}")
    public ApiResult<PersonnelDetailResponse> followDetail(@PathVariable("personCode") String personCode) {
        return ApiResult.success(sasPersonnelService.followDetail(personCode));
    }
}

