package cn.pluss.platform.controller;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.app.MainPageService;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.userApp.UserAppService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequiredArgsConstructor
public class MainPageController {

    @Autowired
    private UserAppService userAppService;

    @Autowired
    private MainPageService promoterMainPageService;

    @Autowired
    private MainPageService agentStaffMainPageService;

    /**
     * @page 商户推广
     * 查询推广页统计数据
     * @return
     */
    @PostMapping("/userApp/queryPromotePageData")
    @ApiOperation(tags = {"页面-商户推广"}, value = "查询推广页统计数据", notes = "查询推广页统计数据", httpMethod = "POST")
    public Result<?> getSpreadData() {
        UserApp userApp = userAppService.queryUserAppByToken();
        Map<String, Object> resultMap;

        if ("agent_staff".equals(userApp.getUserType())) {
            resultMap = agentStaffMainPageService.getSpreadData(userApp.getUserId() + "");
        } else {
            resultMap = promoterMainPageService.getSpreadData(userApp.getUserId() + "");
        }

        return ResultGenerator.genSuccessResult(resultMap);
    }
}
