package com.huiju.estateagents.property.controller;


import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.center.taUser.entity.TaUser;
import com.huiju.estateagents.property.common.UserElement;
import com.huiju.estateagents.property.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.HttpServletRequest;
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(HttpServletRequest request, @RequestParam("visitorLicenseBool") Boolean visitorLicenseBool){
        ResponseBean responseBean = new ResponseBean();
        TaUser userElement = getTaUser(request);
        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(HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        TaUser userElement = getTaUser(request);
        responseBean = taVisitorLicenseSettingService.getVisitorLicense(userElement);
        return responseBean;
    }

}
