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.UAccountPackage;
import org.wfc.user.service.IUAccountPackageService;

import java.util.List;

/**
 * <p>
 * 用户平台-账户套餐表 前端控制器
 * </p>
 *
 * @author sys
 * @since 2025-02-10
 */
@RestController
@RequestMapping("/user/uAccountPackage")
public class UAccountPackageController extends BaseController {

    @Autowired
    private IUAccountPackageService uAccountPackageService;

    @GetMapping("/page")
    public TableDataInfo page(UAccountPackage uAccountPackage) {
        startPage();
        List<UAccountPackage> list = uAccountPackageService.list();
        return getDataTable(list);
    }

    @GetMapping("/list")
    public AjaxResult list(UAccountPackage uAccountPackage) {
        List<UAccountPackage> list = uAccountPackageService.list();
        return success(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody UAccountPackage uAccountPackage) {
        return toAjax(uAccountPackageService.save(uAccountPackage));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody UAccountPackage uAccountPackage) {
        return toAjax(uAccountPackageService.updateById(uAccountPackage));
    }

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

}
