package com.ruixuan.jinniu.controller;


import com.alibaba.fastjson.JSONObject;
import com.ruixuan.common.core.controller.BaseController;
import com.ruixuan.common.core.domain.AjaxResult;
import com.ruixuan.common.core.page.TableDataInfo;
import com.ruixuan.common.utils.Result;
import com.ruixuan.jinniu.entity.KuaishouAccount;
import com.ruixuan.jinniu.service.IKuaishouAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 账户Controller
 *
 * @author ruoyi
 * @date 2023-03-15
 */
@Api(tags = "账户Controller")
@RestController
@RequestMapping("/kuaishou/account")
public class KuaishouAccountController extends BaseController {
    @Autowired
    private IKuaishouAccountService kuaishouAccountService;

    /**
     * 查询未绑定账户
     */
    @ApiOperation(value = "查询未绑定账户")
    @GetMapping("/unboundAccountList")
    public TableDataInfo unboundAccountList(
            @ApiParam("账户ID") @RequestParam(value = "accountId", required = false) Long accountId,
            @ApiParam("快手ID") @RequestParam(value = "ksId", required = false) Long ksId,
            @ApiParam("账户名") @RequestParam(value = "accountName", required = false) String accountName,
            @ApiParam("状态 1-认证，2-未认证") @RequestParam(value = "status", required = false) Long status
    ) {
        startPage();
        List<JSONObject> list = kuaishouAccountService.selectUnboundAccountList(accountId, ksId, accountName, status);
        return getDataTable(list);
    }

    /**
     * 查询账户
     */
    @ApiOperation(value = "查询账户")
    @GetMapping("/list")
    public TableDataInfo list(KuaishouAccount kuaishouAccount) {
        List<KuaishouAccount> list = kuaishouAccountService.selectKuaishouAccountList(kuaishouAccount);
        return getDataTable(list);
    }


    /**
     * 按项目Id获取帐户
     */
    @ApiOperation(value = "按项目Id获取帐户")
    @GetMapping("/getAccountByProjectId")
    public TableDataInfo getAccountByProjectId(@ApiParam("项目ID") @RequestParam(value = "projectId", required = false) Long projectId) {
        List<KuaishouAccount> list = kuaishouAccountService.getAccountByProjectId(projectId);
        return getDataTable(list);
    }


    /**
     * 获取账户详细信息
     */
    @ApiOperation(value = "获取账户详细信息")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(kuaishouAccountService.selectKuaishouAccountById(id));
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @GetMapping(value = "/deleteById")
    public AjaxResult deleteById(@ApiParam("id") @RequestParam(value = "id", required = true) Long id) {
        return AjaxResult.success(kuaishouAccountService.deleteKuaishouAccountById(id));
    }

    /**
     * 认领账户
     */
    @ApiOperation(value = "认领账户")
    @PostMapping("/claimAccount")
    public AjaxResult claimAccount(@RequestBody JSONObject o) {
        return toAjax(kuaishouAccountService.insertKuaishouAccount(o));
    }

    /**
     * 取消认领账户
     */
    @ApiOperation(value = "取消认领账户")
    @GetMapping("/deleteClaimAccount")
    public Result<Object> deleteClaimAccount(@ApiParam("accountId") @RequestParam(value = "accountId", required = true) Long accountId,
                                             @ApiParam("userId") @RequestParam(value = "userId", required = true) Long userId) {
        return kuaishouAccountService.deleteClaimAccount(accountId, userId);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @GetMapping("/edit")
    public Result<Object> edit(KuaishouAccount kuaishouAccount) {
        return kuaishouAccountService.edit(kuaishouAccount);
    }

}