package com.community.huiju.controller;

import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.service.TpRentalHouseServicel;
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.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/5/9
 **/
@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "长租公寓相关的API", description = "长租公寓相关的API")
public class TpRentalHouseController extends BaseController{

    @Autowired
    private TpRentalHouseServicel tpRentalHouseServicel;

    @ApiOperation(value = "长租公寓接口", notes = "长租公寓接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
            @ApiImplicitParam(paramType = "query",dataType = "String",name = "houseName",value = "商圈或者小区"),
            @ApiImplicitParam(paramType = "query",dataTypeClass = Integer.class,name = "rentalTypeValue",value = "1:是整租 2:是合租 3:不限"),
            @ApiImplicitParam(paramType = "query",dataTypeClass = Integer.class,name = "houseTypeValue",value = "1:一室居 2:二室居 3:三室局 4:四室居及以上 5:不限"),
            @ApiImplicitParam(paramType = "query",dataTypeClass = Integer.class,name = "rentalPriceValue",value = "1:1000以内 2:1000-1500 3:1500-2000 4:2000-3000 5:3000-4000 6:4000以上 7:不限"),
            @ApiImplicitParam(paramType = "query",dataTypeClass = Integer.class,name = "priceFluctuateValue",value = "1:价格由低到高 2:价格由高到低  3:默认排序" ),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "communityId",value = "小区编号"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "pageNum",value = "第几页"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "pageSize",value = "一页多少数据")
    })
    @RequestMapping(value = "/rentalhouse",method = RequestMethod.GET)
    public Object getRentalHouse(HttpSession session,
                                    @RequestParam(value = "houseName",required = false ) String houseName,
                                    @RequestParam(value = "rentalTypeValue",required = false) Integer rentalTypeValue,
                                    @RequestParam(value = "houseTypeValue",required = false) Integer houseTypeValue,
                                    @RequestParam(value = "rentalPriceValue",required = false) Integer rentalPriceValue,
                                    @RequestParam(value = "priceFluctuateValue",required = false) Integer priceFluctuateValue,
                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        UserElement userElement = getUserElement(session);
        ResponseBean responseBean = tpRentalHouseServicel.getRentalHouse(userElement,houseName,rentalTypeValue,houseTypeValue,rentalPriceValue,priceFluctuateValue,pageNum,pageSize);
        return responseBean;
    }

    @ApiOperation(value = "长租公寓详情", notes = "长租公寓详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
            @ApiImplicitParam(paramType = "path",dataTypeClass = Integer.class,name = "id",value = "出租房ID"),
    })
    @RequestMapping(value = "/rentalhouse/details/{id}",method = RequestMethod.GET)
    public Object getRentalHouseDetails(HttpSession session,
                                        @PathVariable("id") String id){
        UserElement userElement = getUserElement(session);
        ResponseBean responseBean = tpRentalHouseServicel.getRentalHouseDetails(userElement,id);
        return responseBean;
    }

    @ApiOperation(value = "长租公寓数据字典", notes = "长租公寓数据字典")
    @RequestMapping(value = "/rentalhouse/dictionaries",method = RequestMethod.GET)
    public Object getRentalHousedictionaries(){
        ResponseBean responseBean = tpRentalHouseServicel.getRentalHouseDictionaries();
        return responseBean;
    }




}
