package org.wfc.system.controller;

import cn.hutool.core.collection.CollUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wfc.common.core.web.controller.BaseController;
import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.common.log.annotation.Log;
import org.wfc.common.log.enums.BusinessType;
import org.wfc.system.domain.URateLimit;
import org.wfc.system.service.IURateLimitService;

import java.util.List;

/**
 * <p>
 * 用户平台-带宽限速表 前端控制器
 * </p>
 *
 * @author sys
 * @since 2024-12-20
 */
@RestController
@RequestMapping("/rateLimit")
public class URateLimitController extends BaseController {

    @Autowired
    private IURateLimitService uRateLimitService;

    @GetMapping("/page")
    public TableDataInfo page(URateLimit uRateLimit) {
        startPage();
        List<URateLimit> list = uRateLimitService.list();
        return getDataTable(list);
    }

    @GetMapping("/list")
    public AjaxResult list(URateLimit uRateLimit) {
        List<URateLimit> list = uRateLimitService.list();
        return success(list);
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getById(@PathVariable("id") Long id) {
        return success(uRateLimitService.getById(id));
    }

    @Log(title = "Rate Limit", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody URateLimit uRateLimit) {
        return toAjax(uRateLimitService.save(uRateLimit));
    }

    @Log(title = "Rate Limit", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody URateLimit uRateLimit) {
        return toAjax(uRateLimitService.updateById(uRateLimit));
    }

    @Log(title = "Rate Limit", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(uRateLimitService.removeByIds(CollUtil.newArrayList(ids)));
    }

}
