package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.vo.StoreMembershipCardOrderVo;
import shop.alien.store.service.StoreMembershipCardOrderService;

/**
 * <p>
 * 商家会员卡订单表 前端控制器
 * </p>
 *
 * @author ssk
 * @since 2025-03-11
 */
@Slf4j
@Api(tags = {"会员卡接口"})
@ApiSort(1)
@CrossOrigin
@RestController
@RequestMapping("/store-membership-card-order")
@RequiredArgsConstructor
public class StoreMembershipCardOrderController {

    private final StoreMembershipCardOrderService storeMembershipCardOrderService;

    @ApiOperation("会员卡下单接口")
    @ApiOperationSupport(order = 1)
    @PostMapping(value = "/placeOrder")
    public R placeOrder(@RequestBody StoreMembershipCardOrderVo storeMembershipCardOrderVo) {
        return R.data(storeMembershipCardOrderService.placeOrder(storeMembershipCardOrderVo));
    }

    @ApiOperation("查询该店铺的会员卡信息")
    @ApiOperationSupport(order = 1)
    @GetMapping(value = "/getStoreMembershipCard")
    public R getStoreMembershipCard(@RequestParam(value = "storeId", required = false) String storeId) {
        return R.data(storeMembershipCardOrderService.getStoreMembershipCard(storeId));
    }

    @ApiOperation("会员卡订单查询")
    @ApiImplicitParams({@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页容", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = false),
            @ApiImplicitParam(name = "storeName", value = "门店名称", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "orderCode", value = "订单编号", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "orderStatus", value = "订单状态", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "membershipType", value = "VIP类型", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "purchasePattern", value = "购买类型", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "expirationTime", value = "到期时间", dataType = "Date", paramType = "query", required = false)})
    @GetMapping("/getStoreMembershipCardOrder")
    public R<IPage<StoreMembershipCardOrderVo>> getStoreMembershipCardOrder(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) Integer storeId,
            @RequestParam(required = false) String storeName,
            @RequestParam(required = false) String orderCode,
            @RequestParam(required = false) String orderStatus,
            @RequestParam(required = false) String purchasePattern,
            @RequestParam(required = false) String expirationTime,
            @RequestParam(required = false) String membershipType
    ) {
        return R.data(storeMembershipCardOrderService.getOrderHistory(pageNum, pageSize, storeId, storeName, orderCode, orderStatus, purchasePattern, expirationTime, membershipType));
    }

}
