package co.yixiang.yshop.module.distributor.controller.app.distributor;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.security.core.annotations.PreAuthenticated;
import co.yixiang.yshop.module.distributor.controller.app.distributor.vo.AppDistributorApplyReqVO;
import co.yixiang.yshop.module.distributor.controller.app.distributor.vo.AppDistributorDetailsRespVO;
import co.yixiang.yshop.module.distributor.controller.app.distributor.vo.AppDistributorUpdateReqVO;
import co.yixiang.yshop.module.distributor.service.distributor.DistributorFacade;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

@Slf4j
@RestController
@Tag(name = "APP - 分销商模块")
@RequestMapping("/app/distributor")
public class AppDistributorController {

    @Resource
    private DistributorFacade distributorFacade;

    // 获取详情
    @PreAuthenticated
    @GetMapping("/details")
    @Operation(summary = "分销商详情")
    public CommonResult<AppDistributorDetailsRespVO> getDetails() {
        return success(distributorFacade.getAppDetails());
    }

    // 修改我的资料
    @PreAuthenticated
    @PostMapping("/update")
    @Operation(summary = "修改我的资料")
    public CommonResult<Boolean> appUpdate(@Valid @RequestBody AppDistributorUpdateReqVO reqVO) {
        distributorFacade.appUpdate(reqVO);
        return success(Boolean.TRUE);
    }

    // 申请成为经销商
    @PreAuthenticated
    @PostMapping("/apply")
    @Operation(summary = "申请成为经销商")
    public CommonResult<Boolean> apply(@Valid @RequestBody AppDistributorApplyReqVO reqVO) {
        distributorFacade.apply(reqVO);
        return success(Boolean.TRUE);
    }

}
