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.UAccount;
import org.wfc.user.service.IUAccountService;

import java.util.List;

/**
 * <p>
 * 用户平台-账户表 前端控制器
 * </p>
 *
 * @author sys
 * @since 2024-12-23
 */
@RestController
@RequestMapping("/account")
public class UAccountController extends BaseController {

    @Autowired
    private IUAccountService uAccountService;

    @GetMapping("/page")
    public TableDataInfo page(UAccount uAccount) {
        startPage();
        List<UAccount> list = uAccountService.list();
        return getDataTable(list);
    }

    @GetMapping("/list")
    public AjaxResult list(UAccount uAccount) {
        List<UAccount> list = uAccountService.list();
        return success(list);
    }

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

    @GetMapping(value = "/dashboard")
    public AjaxResult dashboard() {
        return success(uAccountService.getByUser());
    }

    @PostMapping
    public AjaxResult add(@RequestBody UAccount uAccount) {
        return toAjax(uAccountService.save(uAccount));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody UAccount uAccount) {
        return toAjax(uAccountService.updateById(uAccount));
    }

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

}
