package com.ruoyi.brewery.controller;

import com.ruoyi.brewery.domain.DispatchRewardVO;
import com.ruoyi.brewery.domain.WyActivityReward;
import com.ruoyi.brewery.domain.WyBreweryBanner;
import com.ruoyi.brewery.domain.WyRedeemOrder;
import com.ruoyi.brewery.service.IWyActivityRewardService;
import com.ruoyi.brewery.service.IWyBreweryBannerService;
import com.ruoyi.brewery.service.IWyRedeemOrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.RewardStatusConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 品牌方订单管理
 *
 * @author ruoyi
 * @date 2024-12-21
 */
@Api(tags = "品牌方订单管理")
@RestController
@RequestMapping("/brewery/order")
public class BreweryOrderController extends BreweryBaseController {
    @Resource
    private IWyRedeemOrderService orderService;
    @Resource
    private IWyActivityRewardService rewardService;

    /**
     * 查询品牌方兑换订单列表
     */
//    @ApiOperation("查询品牌方兑换订单列表")
//    @PreAuthorize("@bss.hasPermi('brewery:redeemOrder:list')")
//    @GetMapping("/redeemOrderList")
//    public TableDataInfo list(WyRedeemOrder redeemOrder) {
//        startPage();
//        redeemOrder.setBreweryId(SecurityUtils.getBreweryLoginUser().getBreweryId());
//        final List<WyRedeemOrder> wyRedeemOrders = orderService.selectWyRedeemOrderList(redeemOrder);
//        return getDataTable(wyRedeemOrders);
//    }

    /**
     * 查询品牌方活动兑付订单列表
     */
    @ApiOperation("查询品牌方活动兑付订单列表")
    @PreAuthorize("@bss.hasPermi('brewery:rewardOrder:list')")
    @GetMapping("/rewardOrderList")
    public TableDataInfo list(WyActivityReward activityReward) {
        startPage();
        activityReward.setBreweryId(SecurityUtils.getBreweryLoginUser().getBreweryId());
        final List<WyActivityReward> wyActivityRewards = rewardService.selectWyActivityRewardList(activityReward);
        return getDataTable(wyActivityRewards);
    }

    /**
     * 查询品牌方活动兑付订单详情
     */
    @ApiOperation("查询品牌方活动兑付订单详情")
    @PreAuthorize("@bss.hasPermi('brewery:rewardOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getRewardOrderInfo(@PathVariable("id") Long id) {
        final WyActivityReward wyActivityReward = rewardService.selectWyActivityRewardById(id);
        validateOwner(wyActivityReward.getBreweryId());
        return success(wyActivityReward);
    }

    /**
     * 品牌方兑付订单发货
     */
    @ApiOperation("品牌方兑付订单发货")
    @PreAuthorize("@bss.hasPermi('brewery:banner:edit')")
    @Log(title = "品牌方兑付订单发货", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/dispatchReward")
    public AjaxResult dispatchReward(@Validated @RequestBody DispatchRewardVO dispatchRewardVO) {
        final WyActivityReward wyActivityReward = rewardService.selectWyActivityRewardById(dispatchRewardVO.getRewardId());
        validateOwner(wyActivityReward.getBreweryId());
        wyActivityReward.setRewardStatus(RewardStatusConstants.Shipped); //兑付订单状态设为已发货
        return success("订单已发货");
    }
}
