package com.community.huiju.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.model.HotelRoom;
import com.community.huiju.service.IHotelRoomService;
import com.community.huiju.model.Hotel;
import com.community.huiju.service.IHotelService;
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.RequestBody;
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 com.community.huiju.common.base.BaseController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 * 酒店 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-05-13
 */
@RestController
@RequestMapping("/")
@Api(value = "", description = "酒店管理API")
public class HotelController extends BaseController {
    @Autowired
    private IHotelService iHotelService;

    @Autowired
    private IHotelRoomService tpHotelRoomService;


    @ApiOperation(value = "房屋列表", notes = "房屋列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "roomNo:房间号" +
                    "roomName:房间名称" +
                    "price:价格" +
                    "roomStatus:(1:是已上架 2:是已下架)" +
                    "beginTime:开始时间"+
                    "endTime:结束时间"+
                    "sort:权重")
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/hotelRoomList", method = RequestMethod.POST)
    public ResponseBean hotelRoom(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = iHotelService.hotelRoomLiset(parameter,userElement.getCommunityId());
        return responseBean;
    }

    @ApiOperation(value = "添加房间", notes = "添加房间")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "roomNo:房间号" +
                    "roomName:房间名称" +
                    "price:价格" +
                    "roomStatus:(1:是已上架 2:是已下架)" +
                    "remark:(描述)"+
                    "sort:权重")
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/hotelRoomAdd", method = RequestMethod.POST)
    public ResponseBean hotelRoomAdd(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = iHotelService.hotelRoomAdd(parameter,userElement);
        return responseBean;
    }

    @ApiOperation(value = "查询当前房间信息", notes = "查询当前房间信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "id:房间ID")})
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/getRoom", method = RequestMethod.POST)
    public ResponseBean getRoom(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean responseBean= new ResponseBean<>();

       JSONObject object= JSONObject.parseObject(parameter);
        Integer id= object.getInteger("id");
         HotelRoom totelRoom= tpHotelRoomService.getById(id);
         responseBean.addSuccess(totelRoom);
         return responseBean;
    }
    @ApiOperation(value = "编辑房间", notes = "编辑房间")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "id:房间ID，roomNo:房间号" +
                    "roomName:房间名称" +
                    "price:价格" +
                    "roomStatus:(1:是已上架 2:是已下架)" +
                    "remark:(描述)"+
                    "sort:权重")
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/hotelRoomEdit", method = RequestMethod.POST)
    public ResponseBean hotelRoomEdit(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = iHotelService.hotelRoomEdit(parameter,userElement);
        return responseBean;
    }

    @ApiOperation(value = "修改当前房间上架或下架状态", notes = "修改当前房间上架或下架状态")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "id:[]房间ID，roomStatus:(1:是已上架 2:是已下架)"
            )})
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/hotelRoomRoomStatus", method = RequestMethod.POST)
    public ResponseBean hotelRoomRoomStatus(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = iHotelService.hotelRoomRoomStatus(parameter,userElement);
        return responseBean;
    }
    
    @ApiOperation(value = "根据小区获取酒店数据", notes = "根据搜索条件获取角色列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
    })
    @RequestMapping(value = "/getHotelData",method = RequestMethod.GET)
    public ResponseBean getHotelData(HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        Hotel hotel = iHotelService.getHotelData(userElement);
        responseBean.addSuccess(hotel);
        return responseBean;
    }
    
    @ApiOperation(value = "添加酒店", notes = "添加酒店")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Hotel", name = "hotel", value = "酒店"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token")
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/addHotel", method = RequestMethod.POST)
    public ResponseBean addHotel(@RequestBody Hotel hotel, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = iHotelService.addHotel(hotel,userElement);
        return responseBean;
    }
}
