package com.community.huiju.controller;


import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.common.base.BaseController;
import com.community.huiju.service.ITaVisitorLicenseSettingService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 * 录入访客车牌功能开关表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-05-27
 */
@RestController
@RequestMapping("/")
@Api(value = "录入访客车牌功能开关", description = "录入访客车牌功能开关")
public class TaVisitorLicenseSettingController extends BaseController {

    @Autowired
    private ITaVisitorLicenseSettingService taVisitorLicenseSettingService;

    @ApiOperation(value = "是否开启访客邀请车辆", notes = "是否开启访客邀请车辆")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = Boolean.class, paramType = "form", name = "visitorLicenseBool", value = "true 表示开启  false 关闭"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "header", name = "X-Auth-Token", value = "Token")
    })
    @RequestMapping(value = "/visitor/saveOrDelete", method = RequestMethod.POST)
    public ResponseBean saveOrDelete(HttpSession session, @RequestParam("visitorLicenseBool") Boolean visitorLicenseBool){
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = taVisitorLicenseSettingService.saveOrDelete(userElement, visitorLicenseBool);

        return responseBean;
    }


    @ApiOperation(value = "查看是否开启访客车辆邀请", notes = "查看是否开启访客车辆邀请")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token")
    })
    @RequestMapping(value = "/visitor", method = RequestMethod.GET)
    public ResponseBean getVisitorLicense(HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = taVisitorLicenseSettingService.getVisitorLicense(userElement);
        return responseBean;
    }

}
