package org.wfc.user.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.user.domain.UBillRule;
import org.wfc.user.service.IUBillRuleService;

import java.util.List;

/**
 * <p>
 * 用户平台-计费规则表 前端控制器
 * </p>
 *
 * @author sys
 * @since 2025-01-06
 */
@RestController
@RequestMapping("/user/uBillRule")
public class UBillRuleController extends BaseController {

    @Autowired
    private IUBillRuleService uBillRuleService;

    @GetMapping("/page")
    public TableDataInfo page(UBillRule uBillRule) {
        startPage();
        List<UBillRule> list = uBillRuleService.list();
        return getDataTable(list);
    }

    @GetMapping("/list")
    public AjaxResult list(UBillRule uBillRule) {
        List<UBillRule> list = uBillRuleService.list();
        return success(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody UBillRule uBillRule) {
        return toAjax(uBillRuleService.save(uBillRule));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody UBillRule uBillRule) {
        return toAjax(uBillRuleService.updateById(uBillRule));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(uBillRuleService.removeByIds(CollUtil.newArrayList(ids)));
    }

}
