package com.community.huiju.controller;

import com.alibaba.fastjson.JSONObject;
import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.service.ITaUserService;
import com.community.huiju.service.TaUserVerifyServicel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * app端用户审核
 *
 * @author weiximei
 */
@RestController
@RequestMapping("/")
@Api(value = "app端用户审核表", description = "app端用户审核表")
public class UserVerifyController extends BaseController {

    @Autowired
    private TaUserVerifyServicel taUserVerifyServicel;

    @RequestMapping(value = "/user/verify/{userVerifyId}", method = RequestMethod.GET)
    @ApiOperation(value = "获取 一个房产信息", notes = "获取 一个房产信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "userVerifyId", value = "审核房产 id"),
    })
    public ResponseBean getUserVerify(HttpSession session, @PathVariable("userVerifyId") Integer userVerifyId) {
        ResponseBean responseBean = taUserVerifyServicel.getToAuditNotApproved(userVerifyId);
        return responseBean;
    }

    @RequestMapping(value = "/user/verify/add", method = RequestMethod.POST)
    @ApiOperation(value = "添加一个审核的房产", notes = "添加一个审核的房产")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "communityId小区编号;roleName角色名称;phaseId期;buildingId楼栋;unitId单元;levelId楼层;roomNoId户号")
    })
    public ResponseBean addUserVerify(@RequestBody String parameter, HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = taUserVerifyServicel.addUserVerify(userElement, parameter);
        return responseBean;
    }

    @RequestMapping(value = "/user/verify/delete/{userVerifyId}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除一个审核的房产", notes = "删除一个审核的房产")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "userVerifyId", value = "审核房产 id")
    })
    public ResponseBean deleteUserVerify(@PathVariable("userVerifyId") Integer userVerifyId, HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        responseBean = taUserVerifyServicel.deleteUserVerify(userVerifyId);
        return responseBean;
    }

    @RequestMapping(value = "/current_user/verify/delete/{userVerifyId}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除当前用户 关联的房产", notes = "删除当前用户 关联的房产")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "userVerifyId", value = "审核房产 id"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token")
    })
    public ResponseBean deleteCurrentUserVerify(@PathVariable("userVerifyId") Integer userVerifyId, HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = taUserVerifyServicel.deleteCurrentUserVerify(userElement, userVerifyId);
        return responseBean;
    }

    @RequestMapping(value = "/user/verify/list", method = RequestMethod.GET)
    @ApiOperation(value = "获取 当前用户关联的房产列表", notes = "获取 当前用户关联的房产列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token")
    })
    public ResponseBean getByCurrentUser(HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = taUserVerifyServicel.getByCurrentUser(userElement);
        return responseBean;
    }


    @RequestMapping(value = "/user/verify/{userVerifyId}", method = RequestMethod.PUT)
    @ApiOperation(value = "业主审核用户", notes = "业主审核用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "userVerifyId", value = "审核房产 id"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "userVerifyStatus审核 1是审核通过   2是审核不通过;remark备注"),
    })
    public ResponseBean verifyUser(HttpSession session,
                                   @PathVariable("userVerifyId") Integer userVerifyId,
                                   @RequestBody String parameter) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        JSONObject jsonObject = JSONObject.parseObject(parameter);
        responseBean = taUserVerifyServicel.verifyUser(userElement, userVerifyId, jsonObject.getString("userVerifyStatus"), jsonObject.getString("remark"));
        return responseBean;
    }


    @RequestMapping(value = "/user_verify/add", method = RequestMethod.POST)
    @ApiOperation(value = "添加一个审核的房产 大苏", notes = "添加一个审核的房产 大苏")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "userId用户编号;communityId小区编号;roleName角色名称;phaseId期;buildingId楼栋;unitId单元;levelId楼层;roomNoId户号")
    })
    public ResponseBean addDaSuUserVerify(@RequestBody String parameter, HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        responseBean = taUserVerifyServicel.addDaSuUserVerify(parameter);
        return responseBean;
    }

}
