package com.kym.miniapp.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.kym.common.R;
import com.kym.common.controller.IController;
import com.kym.entity.WashOrder;
import com.kym.entity.common.PageParams;
import com.kym.entity.queryParams.WashOrderQueryParams;
import com.kym.entity.vo.WashOrderVo;
import com.kym.service.WashOrderService;
import com.kym.service.cache.KymCache;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 洗车订单表 前端控制器
 * </p>
 *
 * @author skyline
 * @since 2024-09-11
 */
@RestController
@RequestMapping("/wash-order")
public class WashOrderController extends IController {

    private final WashOrderService washOrderService;

    public WashOrderController(WashOrderService washOrderService) {
        this.washOrderService = washOrderService;
    }


    /**
     * 获取当前用户订单列表
     *
     * @param params
     * @return
     */
    @GetMapping(value = "/listMyWashOrder")
    R<?> listMyWashOrder(@ModelAttribute PageParams params) {
        return resp(() -> washOrderService.listMyWashOrder(params));
    }

    /**
     * 获取当前用户订单详情
     *
     * @param params
     * @return
     */
    @GetMapping(value = "/detailWashOrder")
    R<?> detailWashOrder(@ModelAttribute WashOrderQueryParams params) {
        return resp(() -> {
            WashOrder order = washOrderService.queryOrder(params);
            WashOrderVo vo = new WashOrderVo();
            BeanUtils.copyProperties(order, vo);
            vo.setStationName(KymCache.INSTANCE.getStationNameById(order.getStationId()));
            return vo;
        });
    }

    /**
     * 获取停车优惠
     *
     * @param unionid
     * @return
     */
    @SaIgnore
    @GetMapping(value = "/getParkingDiscounts/{unionid}")
    R<?> getParkingDiscounts(@PathVariable String unionid) {
        return resp(() -> washOrderService.getParkingDiscounts(unionid));
    }

}
