package com.kexue.skills.controller;

import com.github.pagehelper.PageInfo;
import com.kexue.skills.annotation.RequireAuth;
import com.kexue.skills.common.CommonResult;
import com.kexue.skills.entity.Account;
import com.kexue.skills.entity.dto.AccountDto;
import com.kexue.skills.service.AccountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Account)表控制层
 * 账户管理控制器
 *
 * @author 王志维
 * @since 2025-02-21 23:01:48
 */
@Tag(name = "账户管理 api")
@RestController
@RequestMapping("/api/account")
public class AccountController {
    /**
     * 服务对象
     */
    @Resource
    private AccountService accountService;

    /**
     * 分页查询
     *
     * @param queryDto 查询参数
     * @return 分页结果
     */
    @Operation(summary = "分页查询账户", description = "分页查询账户")
    @PostMapping("/pageList")
    @RequireAuth
    public CommonResult<PageInfo<Account>> getPageList(@RequestBody AccountDto queryDto) {
        return CommonResult.success(this.accountService.getPageList(queryDto));
    }

    /**
     * 查询列表
     *
     * @param queryDto 查询参数
     * @return 列表结果
     */
    @Operation(summary = "查询账户列表", description = "查询账户列表")
    @PostMapping("/list")
    @RequireAuth
    public CommonResult<List<Account>> getList(@RequestBody AccountDto queryDto) {
        return CommonResult.success(this.accountService.getList(queryDto));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param accountId 主键
     * @return 单条数据
     */
    @Operation(summary = "通过ID查询账户", description = "通过ID查询账户")
    @PostMapping("/queryById/{accountId}")
    @RequireAuth
    public CommonResult<Account> queryById(@Parameter(description = "账户ID") @PathVariable("accountId") Long accountId) {
        return CommonResult.success(this.accountService.queryById(accountId));
    }

    /**
     * 通过用户ID查询单条数据
     *
     * @param userId 用户ID
     * @return 单条数据
     */
    @Operation(summary = "通过用户ID查询账户", description = "通过用户ID查询账户")
    @PostMapping("/queryByUserId/{userId}")
    @RequireAuth
    public CommonResult<Account> queryByUserId(@Parameter(description = "用户ID") @PathVariable("userId") Long userId) {
        return CommonResult.success(this.accountService.queryByUserId(userId));
    }
}