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.queryParams.DeviceQueryParams;
import com.kym.service.WashDeviceService;
import org.springframework.web.bind.annotation.*;

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

    private final WashDeviceService washDeviceService;

    public WashDeviceController(WashDeviceService washDeviceService) {
        this.washDeviceService = washDeviceService;
    }

    @SaIgnore
    @GetMapping("/listWashDevice")
    R<?> listWashDevice(@ModelAttribute DeviceQueryParams params){
        return resp(() ->washDeviceService.listWashDevice(params));
    }

    /**
     * 根据短编号查询设备信息
     *
     * @param shortId
     * @return
     */
    @GetMapping(value = "/queryDevice/{shortId}")
    R<?> queryDevice(@PathVariable("shortId") String shortId) {
        return resp(() -> washDeviceService.getDevice(shortId));
    }

    /**
     * 启动设备创建订单
     *
     * @param shortId
     * @return
     */
    @PostMapping(value = "/startDevice/{shortId}")
    R<?> startDevice(@PathVariable("shortId") String shortId) {
        return resp(() -> washDeviceService.startDevice(shortId));
    }

    /**
     * 停止设备关闭订单
     *
     * @param shortId
     * @return
     */
    @PostMapping(value = "/stopDevice/{shortId}")
    R<?> stopDevice(@PathVariable("shortId") String shortId) {
        return resp((t) -> washDeviceService.stopDevice(shortId));
    }


}
