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

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.security.core.annotations.PreAuthenticated;
import co.yixiang.yshop.module.distributor.controller.admin.distributorwithdrawalmethod.vo.DistributorWithdrawalMethodCreateReqVO;
import co.yixiang.yshop.module.distributor.controller.admin.distributorwithdrawalmethod.vo.DistributorWithdrawalMethodRespVO;
import co.yixiang.yshop.module.distributor.controller.admin.distributorwithdrawalmethod.vo.DistributorWithdrawalMethodUpdateReqVO;
import co.yixiang.yshop.module.distributor.controller.app.distributor.vo.AppDistributorUpdateReqVO;
import co.yixiang.yshop.module.distributor.controller.app.distributorwages.vo.AppDistributorWagesPageReqVO;
import co.yixiang.yshop.module.distributor.controller.app.distributorwages.vo.AppDistributorWagesPageRespVO;
import co.yixiang.yshop.module.distributor.controller.app.distributorwages.vo.AppDistributorWagesWithdrawReqVO;
import co.yixiang.yshop.module.distributor.dal.dataobject.distributorwageslog.DistributorWagesLogDO;
import co.yixiang.yshop.module.distributor.service.distributorwages.DistributorWagesFacade;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

import java.time.LocalDateTime;
import java.util.List;

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

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

    @Resource
    private DistributorWagesFacade distributorWagesFacade;

    // 我的佣金
    @PreAuthenticated
    @GetMapping("/get")
    @Operation(summary = "我的佣金")
    public CommonResult<AppDistributorWagesPageRespVO> getWages(LocalDateTime[] createTime) {
        return success(distributorWagesFacade.getWages(createTime));
    }

    // 我的佣金分页
    @PreAuthenticated
    @GetMapping("/page")
    @Operation(summary = "我的佣金分页")
    public CommonResult<PageResult<DistributorWagesLogDO>> getWagesPage(AppDistributorWagesPageReqVO reqVO) {
        return success(distributorWagesFacade.getWagesPage(reqVO));
    }


    @PreAuthenticated
    @PostMapping("/withdraw")
    @Operation(summary = "提现")
    public CommonResult<Boolean> withdraw(@Valid @RequestBody AppDistributorWagesWithdrawReqVO reqVO) {
        distributorWagesFacade.withdraw(reqVO);
        return success(Boolean.TRUE);
    }

    @PreAuthenticated
    @PostMapping("/update")
    @Operation(summary = "更新分销商提现方式")
    public CommonResult<Boolean> updateWithdrawalMethod(@Valid @RequestBody DistributorWithdrawalMethodUpdateReqVO updateReqVO) {
        distributorWagesFacade.updateWithdrawalMethod(updateReqVO);
        return success(Boolean.TRUE);
    }

    // 我的提现列表
    @PreAuthenticated
    @GetMapping("/withdrawal-method-list")
    @Operation(summary = "我的提现列表")
    public CommonResult<List<DistributorWithdrawalMethodRespVO>> getWithdrawalMethodList() {
        return success(distributorWagesFacade.getWithdrawalMethodList());
    }

}
