package com.fdkankan.platform.agent.controller.api;


import com.auth0.jwt.JWT;
import com.fdkankan.platform.agent.entity.Agent;
import com.fdkankan.platform.agent.service.IAgentNoticeService;
import com.fdkankan.platform.agent.service.IAgentService;
import com.fdkankan.platform.agent.vo.AgentNoticeVo;
import com.fdkankan.platform.agent.vo.AgentVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 代理商表 前端控制器
 * </p>
 *
 * @author 
 * @since 2021-12-23
 */
@RestController
@RequestMapping("/service/platform/agent")
public class AgentController {

    @Autowired
    IAgentService agentService;
    @Autowired
    IAgentNoticeService agentNoticeService;

    /**
     * 获取代理商信息
     * @return
     */
    @PostMapping(value = "/detail")
    public AgentVo detail(@RequestHeader String token){
        String userName = JWT.decode(token).getClaim("userName").asString();
        String agentId = userName.split(":")[1];
        Agent agent = agentService.getAgentById(agentId);
        AgentVo rsp =  new AgentVo();
        BeanUtils.copyProperties(agent, rsp);
        return rsp;
    }

    /**
     * 获取代理商公告
     */
    @PostMapping(value = "/notice")
    public AgentNoticeVo notice() {
        return  agentNoticeService.getAgentNotice();
    }
}

