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

import java.util.List;

/**
 * <p>
 * 用户平台-计费规则表 前端控制器
 * </p>
 *
 * @author sys
 * @since 2025-01-07
 */
@RestController
@RequestMapping("/billRule")
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));
    }

    @Log(title = "Billing Rule", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UBillRule uBillRule) {
        return toAjax(uBillRuleService.save(uBillRule));
    }

    @Log(title = "Billing Rule", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UBillRule uBillRule) {
        return toAjax(uBillRuleService.updateById(uBillRule));
    }

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

}
