package com.community.huiju.controller;

import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.model.TpShop;
import com.community.huiju.service.TpShopServicel;
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/10
 **/
@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "线下商铺的API", description = "线下商铺的API")
public class TpShopController extends BaseController{
    @Autowired
    private TpShopServicel tpShopServicel;

    @ApiOperation(value = "获取所有线下商铺", notes = "获取所有线下商铺")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
            @ApiImplicitParam(paramType = "query",dataType = "String",name = "shopName",value = "搜所名称"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "tpShopTypeId",value = "商铺类型"),
            @ApiImplicitParam(paramType = "query", dataType = "integer", name = "pageNum", value = "分页第几页"),
            @ApiImplicitParam(paramType = "query", dataType = "integer", name = "pageSize", value = "分页每页长度")
    })
    @RequestMapping(value = "/shop",method = RequestMethod.GET)
    public Object getShop(HttpSession session,
                          @RequestParam(value = "shopName",required = false ) String houseName,
                          @RequestParam(value = "tpShopTypeId",required = false ) Integer tpShopTypeId,
                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        UserElement userElement = getUserElement(session);
        ResponseBean responseBean = tpShopServicel.getShop(userElement,houseName,tpShopTypeId,pageNum,pageSize);
        return responseBean;
    }

    @ApiOperation(value = "获取线下商铺详情", notes = "获取线下商铺详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
            @ApiImplicitParam(paramType = "path",dataType = "integer",name = "id",value = "商铺ID"),
    })
    @RequestMapping(value = "/shop/details/{id}",method = RequestMethod.GET)
    public Object getShopDetails(HttpSession session,
                                 @PathVariable("id") String id){
        UserElement userElement = getUserElement(session);
        ResponseBean responseBean = tpShopServicel.getShopDetails(userElement,Integer.valueOf(id));
        return responseBean;
    }

    @ApiOperation(value = "首页商铺信息", notes = "首页商铺信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
    })
    @RequestMapping(value = "/getShopCommunity",method = RequestMethod.GET)
    public Object getShopCommunity(HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean responseBean = tpShopServicel.getShopCommunity(userElement);
        return responseBean;
    }



}
