package com.community.huiju.controller;

import com.aliyun.oss.OSSClient;
import com.community.commom.mode.ResponseBean;
import com.community.huiju.model.ToBanner;
import com.community.huiju.service.BannerServiceI;
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.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.util.Date;
import java.util.List;

/**
 * @author weichaochao
 * @Title: BannerController
 * @Description: 首页运营banner入口类
 * @date 2018/10/22
 */
@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "首页运营banner的API", description = "首页运营banner的API")
public class BannerController {

    @Autowired
    private BannerServiceI bannerService;

    @ApiOperation(value = "获取首页运营banner接口详情", notes = "获取首页运营banner详情")
    @RequestMapping(value = "/banner/{bannerId}", method = RequestMethod.GET)
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "path", dataType = "integer", name = "bannerId", value = "运营banner图Id") })
    public ResponseBean selectToBannerImg(@PathVariable("bannerId")Integer bannerId){
        ResponseBean responseBean = new ResponseBean();
        ToBanner toBannerList = bannerService.viewBannerImg(bannerId);
        responseBean.addSuccess(toBannerList);
        return responseBean;
    }

    @ApiOperation(value = "获取首页运营所有banner接口", notes = "获取首页所有运营banner")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "bannerPosition", value = "banner位: 1首页banner 2服务端"),
    })
    @RequestMapping(value = "/banners", method = RequestMethod.GET)
    public ResponseBean selectAllToBannerImg(@RequestParam("bannerPosition") Integer bannerPosition){
        ResponseBean responseBean = new ResponseBean();
        List<ToBanner> toBannerList = bannerService.viewAllBannerImg(bannerPosition);
        responseBean.addSuccess(toBannerList);
        return responseBean;
    }

    @ApiOperation(value = "获取广告banner接口", notes = "获取广告运营banner")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "bannerPosition", value = " 3 广告banner"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "communityId", value = "小区编号")
    })
    @RequestMapping(value = "/banners/advertising", method = RequestMethod.GET)
    public ResponseBean selectAllToBannerImg(@RequestParam("bannerPosition") Integer bannerPosition, @RequestParam(value = "communityId", required = false) Integer communityId){
        ResponseBean responseBean = new ResponseBean();
        List<ToBanner> toBannerList = bannerService.viewAllBannerImgAndCommunityId(bannerPosition, communityId);
        responseBean.addSuccess(toBannerList);
        return responseBean;
    }

}
