package com.huimv.admin.system.controller;


import com.huimv.admin.system.entity.Account;
import com.huimv.admin.system.entity.dto.UpdateAccountDto;
import com.huimv.admin.system.service.IAccountService;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author astupidcoder
 * @since 2021-09-09
 */
@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private IAccountService iAccountService;

    @RequestMapping("/new")
    public Result newAccount(@RequestParam(name = "userId") Integer userId){
        return iAccountService.newAccount(userId);
    }

    @RequestMapping("/cancel")
    public Result cancelAccount(@RequestParam(name = "id") Integer id,
                                @RequestParam(name = "accountStatus") Integer accountStatus){
        return iAccountService.cancelAccount(id,accountStatus);
    }

    @RequestMapping("/remove")
    public Result removeAccount(@RequestParam(name = "ids") List<Integer> ids){
        return  iAccountService.removeAccount(ids);
    }


    @RequestMapping("/list")
    public Result listAccount(){
        return iAccountService.findAll();
    }

    @RequestMapping("/setAccountStatus")
    public Result setAccountStatus(@RequestParam(name = "ids") List<Integer> ids, @RequestParam(name = "status") Integer status){
        /* 设置账号状态 */
        return iAccountService.setAccountStatus(ids,status);
    }

    @PostMapping("/update")
    public Result update(@RequestBody Account account){
        /* 设置账号状态 */
        return new Result(ResultCode.SUCCESS, iAccountService.updateById(account));
    }


    @GetMapping("/findOne")
    public Result findOne(Integer id){
        return new Result(ResultCode.SUCCESS, iAccountService.getById(id));
    }



}
