package com.community.huiju.controller;

import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.service.IBuildingOwnerInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * version V1.0
 * class_name: $METHOD_NAME$
 * param: $METHOD_PARAM$
 * describe: TODO
 * creat_user:fannaixi
 * creat_time: 2019/3/28
 **/
@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "楼栋资料库API",description = "楼栋资料库API")
public class IBuildingOwnerInfoController extends BaseController {

    @Autowired
    private IBuildingOwnerInfo iBuildingOwnerInfo;

    @RequestMapping(value = "/building/select/address", method = RequestMethod.GET)
    @ApiOperation(value = "根据 小区/期/楼栋/单元/楼层/户号 (申请注册绑定)", notes = "根据 小区/期/楼栋/单元/楼层/户号")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "communityId", value = "小区"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "phaseId", value = "期"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "buildingId", value = "楼栋"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "unitId", value = "单元"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "levelId", value = "楼层")
    })
    public ResponseBean selectByAddress(@RequestParam("communityId") Integer communityId,
                                        @RequestParam(value = "phaseId", required = false) Integer phaseId,
                                        @RequestParam(value = "buildingId",required = false) Integer buildingId,
                                        @RequestParam(value = "unitId", required = false) Integer unitId,
                                        @RequestParam(value = "levelId", required = false) Integer levelId) {

        ResponseBean responseBean = new ResponseBean();
        responseBean = iBuildingOwnerInfo.selectBuildList(communityId, phaseId, buildingId, unitId, levelId);
        return responseBean;

    }

    @RequestMapping(value = "/building/has", method = RequestMethod.GET)
    @ApiOperation(value = "根据 小区、期、楼栋、单元、楼层、户号 （并校验这个用户，是否绑定了这个房产）", notes = "根据 小区、期、楼栋、单元、楼层、户号")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "communityId", value = "小区"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "phaseId", value = "期"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "buildingId", value = "楼栋"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "unitId", value = "单元"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "levelId", value = "楼层"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "roomNoId", value = "户号"),
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token")
    })
    public ResponseBean hasBuilding(@RequestParam(value = "communityId", required = false) Integer communityId,
                                    @RequestParam(value = "phaseId", required = false) Integer phaseId,
                                   @RequestParam(value = "buildingId",required = false) Integer buildingId,
                                   @RequestParam(value = "unitId", required = false) Integer unitId,
                                   @RequestParam(value = "levelId", required = false) Integer levelId,
                                   @RequestParam(value = "roomNoId", required = false) Integer roomNoId,
                                   HttpSession session){

        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iBuildingOwnerInfo.hasBuild(userElement, communityId ,phaseId, buildingId, unitId, levelId, roomNoId);
        return responseBean;
    }

}
