package com.reyun.saas.web.controller.user;

import com.reyun.saas.common.framework.ApiRestController;
import com.reyun.saas.common.restResult.RestResult;
import com.reyun.saas.mob.user.domain.User;
import com.reyun.saas.mob.user.service.SubUserService;
import com.reyun.saas.security.utils.SecurityUtils;
import com.reyun.saas.web.aop.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@Api(value = "/subUserAuth", tags = "子用户权限")
@ApiRestController("subUserAuth")
public class SubUserAuthController {

    @Autowired
    private SubUserService subUserService;


    @Log(value = 1, description = "创建子账号", type = 1,insertDB = true)
    @ApiOperation(value = "创建子账号", notes = "需要的参数: 邮箱:username  姓名: actualName  备注信息: remark  角色: roleCategory" , produces = "application/json")
    @PostMapping("createSubUser")
    public RestResult create(@RequestBody User user){
        return subUserService.createSubUser(SecurityUtils.getLoginUserId(),user);
    }

    @Log(value = 4, description = "回写子账号信息", type = 1)
    @ApiOperation(value = "回写子账号信息", notes = "", produces = "application/json")
    @GetMapping("/{userId}/findUser")
    public RestResult findSubUser(@PathVariable("userId")Long userId){
        return subUserService.findSubUser(SecurityUtils.getLoginUserId(),userId);
    }

    @Log(value = 3, description = "修改子账号信息", type = 1,insertDB = true)
    @ApiOperation(value = "修改子账号信息", notes = "需要的参数: 邮箱:username  姓名: actualName  备注信息: remark  角色: roleCategory" , produces = "application/json")
    @PutMapping("/updateSubUser")
    public RestResult update(@RequestBody User user){
        return subUserService.updateSubUser(SecurityUtils.getLoginUserId(),user);
    }


    @Log(value = 4, description = "用户列表", type = 1)
    @ApiOperation(value = "用户列表", notes = "", produces = "application/json")
    @GetMapping("/Infos")
    public RestResult Infos(String status,String roleCategory,String desc,String search){
        return subUserService.infos(SecurityUtils.getLoginUserId(),status,roleCategory,desc,search);
    }


    @Log(value = 3, description = "修改用户启用状态", type = 1,insertDB = true)
    @ApiOperation(value = "修改用户启用状态", notes = "", produces = "application/json")
    @PutMapping("/updateUsingStatus/{userId}/{status}")
    public RestResult updateUsingStatus(@PathVariable("userId")Long userId,@PathVariable("status")Boolean status){
        return subUserService.updateUsingStatus(SecurityUtils.getLoginUserId(),userId,status);
    }

    @Log(value = 0, description = "重新发送激活邮件", type = 1,insertDB = true)
    @ApiOperation(value = "重新发送激活邮件", notes = "", produces = "application/json")
    @GetMapping("{userId}/resendMail")
    public RestResult resendMail(@PathVariable("userId")Long userId){
        return subUserService.resendMail(SecurityUtils.getLoginUserId(),userId);
    }

    @Log(value = 2, description = "删除未激活子账号", type = 1,insertDB = true)
    @ApiOperation(value = "删除未激活子账号", notes = "", produces = "application/json")
    @DeleteMapping("{userId}/deleteSubUser")
    public RestResult deleteSubUser(@PathVariable("userId")Long userId){
        return subUserService.deleteSubUser(SecurityUtils.getLoginUserId(),userId);
    }

    @Log(value = 3, description = "分配权限", type = 1,insertDB = true)
    @ApiOperation(value = "分配权限", notes = "", produces = "application/json")
    @PostMapping("/addAuth")
    public RestResult addAuth(@RequestBody User user){
        return subUserService.addAuth(SecurityUtils.getLoginUserId(),user);
    }

    @Log(value = 4, description = "查询子账号权限", type = 1,insertDB = true)
    @ApiOperation(value = "查询子账号权限", notes = "", produces = "application/json")
    @GetMapping("{userId}/findAuth")
    public RestResult findAuth(@PathVariable("userId")Long userId){
        return subUserService.findAuth(SecurityUtils.getLoginUserId(),userId);
    }




}
