package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.PartnerUserHolder;
import com.cool.store.request.order.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.ExportService;
import com.cool.store.service.order.MiniStoreOrderService;
import com.cool.store.vo.order.*;

import javax.validation.Valid;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Auther zx_szh
 * @Date 2026/2/6 14:34
 * @Version 1.0
 */
@Api(tags = "PC标准店-店型")
@RestController
@RequestMapping("/pc/storeOrder")
@RequiredArgsConstructor
public class StoreOrderController {

    private final MiniStoreOrderService miniStoreOrderService;
    private final ExportService exportService;

    @ApiOperation("订单 立规确认 加盟商确认")
    @PostMapping("/passOrder")
    public ResponseResult<Boolean> passOrder(@RequestBody OrderAuditRecordRequest request) {
        return ResponseResult.success(miniStoreOrderService.passOrder(request, CurrentUserHolder.getUser()));
    }

    @ApiOperation("订单 审批拒绝 废弃")
    @PostMapping("/rejectOrder")
    public ResponseResult<Boolean> rejectOrder(@RequestBody OrderAuditRecordRequest request) {
        return ResponseResult.success(miniStoreOrderService.rejectOrder(request,CurrentUserHolder.getUser()));
    }

    @ApiOperation("订单详情")
    @GetMapping("/detail")
    public ResponseResult<MiniStoreOrderDetailVO> detail(@RequestParam("orderId") Long orderId) {
        return ResponseResult.success(miniStoreOrderService.getDetail(orderId));
    }

    @ApiOperation("获取当前门店最新的订单")
    @GetMapping("/getLatestOrderByShopId")
    public ResponseResult<MiniStoreOrderDetailVO> getLatestOrderByShopId(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(miniStoreOrderService.getLatestOrderByShopId(shopId));
    }

    @ApiOperation("订单列表")
    @PostMapping("/list")
    public ResponseResult<PageInfo<PCStoreOrderListVO>> list(@RequestBody PCStoreOrderQueryRequest request) {
        return ResponseResult.success(miniStoreOrderService.list(request));
    }

    @ApiOperation("付款流水明细")
    @GetMapping("/payList")
    public ResponseResult<List<WalletPayVO>> payList(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(miniStoreOrderService.payList(shopId));
    }

    @ApiOperation("批量更新订单配置项数量-只可修改数量 不能调整选项")
    @PostMapping("/batchUpdateOptionQuantity")
    public ResponseResult<Boolean> batchUpdateOptionQuantity(@RequestBody @Valid PCStoreOrderOptionQuantityUpdateRequest request) {
        return ResponseResult.success(miniStoreOrderService.batchUpdateOptionQuantity(request,CurrentUserHolder.getUser()));
    }

    @ApiOperation("管理订单-可调整选项(编辑选配)")
    @PostMapping("/managerOrder")
    public ResponseResult<Boolean> managerOrder(@RequestBody @Valid PCStoreOrderOptionQuantityUpdateRequest request) {
        return ResponseResult.success(miniStoreOrderService.managerOrder(request,CurrentUserHolder.getUser()));
    }

    @ApiOperation("更换心愿单列表-PC")
    @GetMapping("/wishlist/list")
    public ResponseResult<List<MiniStoreWishlistListVO>> wishlistList(@RequestParam(value = "lineId",required = true) Long lineId,
                                                                      @RequestParam(value = "wishlistStatus",required = true) Integer wishlistStatus) {
        return ResponseResult.success(miniStoreOrderService.wishlistList( lineId,wishlistStatus));
    }

    @ApiOperation("更换心愿单-PC")
    @PostMapping("/wishlist/changeWishlist")
    public ResponseResult<Boolean> wishlistList(@RequestBody ChangeWishlistRequest request) {
        return ResponseResult.success(miniStoreOrderService.changeWishlist(request));
    }


    @ApiOperation("心愿单详情")
    @GetMapping("/wishlist/detail")
    public ResponseResult<MiniStoreWishlistDetailVO> wishlistDetail(@RequestParam("wishlistId") Long wishlistId) {
        return ResponseResult.success(miniStoreOrderService.wishlistDetail(wishlistId));
    }

    @ApiOperation("PC心愿单列表")
    @PostMapping("/wishlist/queryPage")
    public ResponseResult<PageInfo<MiniStoreWishlistListVO>> wishAllList(@RequestBody @Valid WishAllListRequest request) {
        return ResponseResult.success(miniStoreOrderService.wishAllList( request));
    }

    @ApiOperation("心愿单待立规审批")
    @PostMapping("/wishlist/wishlistApprove")
    public ResponseResult<Boolean> wishlistApprove(@RequestBody @Valid WishlistAuditRequest request) {
        return ResponseResult.success(miniStoreOrderService.wishlistApprove(request,CurrentUserHolder.getUser()));
    }

    @ApiOperation("查询当前门店铺位绑定的心愿单")
    @GetMapping("/wishlist/getCurrentShopBindWishlist")
    public ResponseResult<MiniStoreWishlistDetailVO> getCurrentShopBindWishlist(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(miniStoreOrderService.getCurrentShopBindWishlist(shopId));
    }

    @ApiOperation("查询订单设备明细")
    @GetMapping("/queryOrderDeviceDetail")
    public ResponseResult<List<OrderDeviceDetailVO>> queryOrderDeviceDetail(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(miniStoreOrderService.queryOrderDeviceDetailByShopId(shopId));
    }

    @ApiOperation("导出订单设备明细")
    @PostMapping("/exportOrderDeviceDetail")
    public ResponseResult<Long> exportOrderDeviceDetail(@RequestParam("orderId") Long orderId) {
        return ResponseResult.success(exportService.exportOrderDeviceDetail(orderId, CurrentUserHolder.getUser()));
    }

}
