package com.ruoyi.web.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.ruoyi.bst.suit.domain.SuitQuery;
import com.ruoyi.bst.suit.domain.enums.SuitStatus;
import com.ruoyi.bst.suit.service.SuitService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/app/suit")
public class AppSuitController extends BaseController {

    @Autowired
    private SuitService suitService;

    @ApiOperation("获取车型可用套餐列表")
    @GetMapping("/listByModel")
    @Anonymous
    public AjaxResult listByModel(SuitQuery query) {
        if (query.getModelId() == null) {
            return error("车型ID不能为空");
        }
        PageHelper.orderBy("order_num asc");
        query.setStatus(SuitStatus.ENABLED.getCode());
        return success(suitService.selectSuitList(query));
    }

    @ApiOperation("获取套餐详情")
    @GetMapping("/detail")
    public AjaxResult detail(@RequestParam Long id) {
        if (id == null) {
            return error("套餐ID不能为空");
        }
        SuitQuery query = new SuitQuery();
        query.setId(id);
        query.setStatus(SuitStatus.ENABLED.getCode());
        return success(suitService.selectOne(query));
    }

}
