package com.community.huiju.controller;


import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.common.base.BaseController;
import com.community.huiju.service.ITpActivityService;
import com.community.huiju.service.ITpActivitySignInService;
import com.community.huiju.service.ITpActivitySignUpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
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.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 物业web端活动表 前端控制器
 * </p>
 *
 * @author weiximei
 * @since 2018-12-28
 */
@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "活动 Api", description = "活动 Api")
public class ActivityController extends BaseController {

    @Autowired
    private ITpActivityService iTpActivityService;

    @Autowired
    private ITpActivitySignUpService iTpActivitySignUpService;

    @Autowired
    private ITpActivitySignInService iTpActivitySignInService;

    @ApiOperation(value = "查询活动列表数据", notes = "根据条件查询活动列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "pageNum第几页;" +
                    "pageSize一页多少行;activityTitle活动标题;id活动编号")
    })
    @RequestMapping(value = "/activity/list", method = RequestMethod.POST)
    public ResponseBean listQuery(@RequestBody String parameter, HttpSession session){
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTpActivityService.listQuery(parameter, userElement);
        return responseBean;
    }

    @ApiOperation(value = "添加活动", notes = "添加活动")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "activityTitle活动标题;" +
                    "activityCarouselImg轮播图;activityContent活动详情;contentImg活动内容配图;signUpMax活动人数上限;" +
                    "registrationEndTime报名活动结束时间;sort权重;status状态 0 是已作废 1 是已发布   2 是草稿，radio:1是需要二维码，2是不需要")
    })
    @RequestMapping(value = "/activity/add", method = RequestMethod.POST)
    public ResponseBean addActivity(@RequestBody String parameter, HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTpActivityService.addActivity(parameter, userElement);
        return responseBean;
    }

    @ApiOperation(value = "修改活动", notes = "修改活动")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "id活动编号;activityTitle活动标题;" +
                    "activityCarouselImg轮播图;activityContent活动详情;contentImg活动内容配图;signUpMax活动人数上限;" +
                    "registrationEndTime报名活动结束时间;sort权重;status状态 0 是已作废 1 是已发布   2 是草稿，radio:1是需要二维码，2是不需要")
    })
    @RequestMapping(value = "/activity/update", method = RequestMethod.PUT)
    public ResponseBean updateActivity(@RequestBody String parameter, HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTpActivityService.updateActivity(parameter, userElement);
        return responseBean;
    }

    @ApiOperation(value = "活动作废", notes = "活动作废")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "ids", value = "活动id集合")
    })
    @RequestMapping(value = "/activity/invalid", method = RequestMethod.PUT)
    public ResponseBean invalidActivity(@RequestBody List<Integer> ids, HttpSession session){
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTpActivityService.updateStatusInvalid(ids, userElement);
        return responseBean;
    }


    @ApiOperation(value = "活动详情", notes = "活动详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "活动id")
    })
    @RequestMapping(value = "/activity/{id}", method = RequestMethod.GET)
    public ResponseBean invalidActivity(@PathVariable(value = "id") Integer id, HttpSession session){
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTpActivityService.getById(id);
        return responseBean;
    }

    @ApiOperation(value = "查询 活动报名人", notes = "查询 活动报名人")
    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(paramType = "body", dataTypeClass = Integer.class, name = "parameter", value = "userName用户名;phone手机号;pageNum第一页;pageSize一页多少行"),
    })
    @RequestMapping(value = "/signUp", method = RequestMethod.POST)
    public ResponseBean getSignUp(@RequestBody String parameter,
                                  HttpSession session) {

        ResponseBean responseBean = new ResponseBean();
        responseBean = iTpActivitySignUpService.getSignUpUser(parameter);
        return responseBean;
    }

    @ApiOperation(value = "删除 活动报名人", notes = "删除 活动报名人")
    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "编号id"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = String.class, name = "parameter", value = "true表示发送短信;false表示不发送短信"),
    })
    @RequestMapping(value = "/signUp/{id}", method = RequestMethod.DELETE)
    public ResponseBean deleteSignUp(@PathVariable("id") Integer id,
                                     @RequestBody String parameter,
                                     HttpSession session) {

        ResponseBean responseBean = new ResponseBean();
        responseBean = iTpActivitySignUpService.deleteSignUp(id, parameter);
        return responseBean;
    }

    @ApiOperation(value = "获取签到人员列表", notes = "获取签到人员列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "活动id"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = String.class, name = "userName", value = "用户姓名"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = String.class, name = "userTel", value = "用户手机号"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "pageNum", value = "第几页"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "pageSize", value = "一页多少行"),
    })
    @RequestMapping(value = "/activity/signIn/{id}", method = RequestMethod.GET)
    public ResponseBean getActivitySignIn(@PathVariable("id") Integer activityId,
                                          @RequestParam(value = "userName", required = false) String userName,
                                          @RequestParam(value = "userTel", required = false) String userTel,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        ResponseBean responseBean = new ResponseBean();
        responseBean = iTpActivitySignInService.getActivitySignIn(activityId, userName, userTel, pageNum, pageSize);
        return responseBean;
    }

    @ApiOperation(value = "获取活动二维码图片", notes = "获取活动二维码图片")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "活动id"),
    })
    @RequestMapping(value = "/activity/code/{id}", method = RequestMethod.GET)
    public void getActivityCode(@PathVariable("id") Integer activityId, HttpServletRequest request, HttpServletResponse response,
                                        @RequestParam("filename") String filename, @RequestParam("imgName") String imgName) {



    }




}
