package org.dromara.main.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.main.domain.MainOrder;
import org.dromara.main.service.IMainOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单管理
 *
 * @author ruoyi
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/main/order")
public class MainOrderController extends BaseController {

    private final IMainOrderService iMainOrderService;

    /**
     * 查询订单列表
     */
//    @SaCheckPermission("main:order:list")
    @GetMapping("/list")
    public TableDataInfo<MainOrder> list(MainOrder order, PageQuery pageQuery) {
        return iMainOrderService.queryPageList(order, pageQuery);
    }

    /**
     * 获取订单详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("main:order:query")
    @GetMapping("/{id}")
    public R<MainOrder> getInfo(@PathVariable Long id) {
        return R.ok(iMainOrderService.queryById(id));
    }

    /**
     * 新增订单
     */
//    @SaCheckPermission("main:order:add")
    @Log(title = "订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MainOrder order) {
        return toAjax(iMainOrderService.insert(order));
    }

    /**
     * 修改订单
     */
//    @SaCheckPermission("main:order:edit")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MainOrder order) {
        return toAjax(iMainOrderService.update(order));
    }

    /**
     * 删除订单
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("main:order:remove")
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable List<Long> ids) {
        return toAjax(iMainOrderService.deleteWithValidByIds(ids, true));
    }
}
