package com.sv.api.controller;

import com.sv.entity.Venue;
import com.sv.service.api.VenueService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.controller.BaseApiController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 场馆
 *
 * @author lihong
 * @since 2018-08-02
 */
@RestController
public class VenueController extends BaseApiController {

    private final Logger logger = LoggerFactory.getLogger(VenueController.class);

    @Resource
    private VenueService venueService;

    /**
     * 分页查询场馆列表
     */
    @RequestMapping(value = "/venues", method = RequestMethod.GET)
    public ResponseDTO findPage(Pagination pagination, @RequestParam("type") Integer type,
                                @RequestParam("longitude") String longitude, @RequestParam("latitude") String latitude) {
        return ResponseDTO.ok()
                .setPagination(venueService.findPages(pagination, type, longitude, latitude));
    }

    /**
     * 地图查询场馆
     *
     * @param type
     * @param longitude
     * @param latitude
     * @param zoom      地图缩放等级
     * @return
     */
    @RequestMapping(value = "/venues/map", method = RequestMethod.GET)
    public ResponseDTO findPage(@RequestParam("type") Integer type, @RequestParam("longitude") String longitude, @RequestParam("latitude") String latitude, @RequestParam("zoom") Integer zoom) {
        return ResponseDTO.ok().addAttribute("venues", venueService.findVenuesForMap(type, longitude, latitude, zoom));
    }

    /**
     * 查询场馆信息
     */
    @RequestMapping(value = "/venue/{id}", method = RequestMethod.GET)
    public ResponseDTO findById(@PathVariable("id") Integer id) {
        return ResponseDTO.ok()
                .addAttribute("venue", venueService.findById(id));
    }

    /**
     * 查询场馆信息
     */
    @RequestMapping(value = "/venue/number", method = RequestMethod.GET)
    public ResponseDTO findById() {
        Venue venue = venueService.findById(32);
        return ResponseDTO.ok()
                .addAttribute("number", venue.getNumber());
    }

    /**
     * 删除场馆
     */
    @RequestMapping(value = "/venue/delete", method = RequestMethod.POST)
    public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
        venueService.deleteByIds(ids);
        return ResponseDTO.ok("删除成功");
    }


    /**
     * 场馆详情
     */
    @RequestMapping(value = "/venue/detail", method = RequestMethod.POST)
    public ResponseDTO detail(@RequestParam("venueId") Integer venueId) {
        return ResponseDTO.ok().addAttribute("venues", venueService.findByVenueId(venueId));
    }

    /**
     * 我要进场
     *
     * @param venueId 场馆Id
     * @return
     */
    @RequestMapping(value = "/venue/join", method = RequestMethod.GET)
    public ResponseDTO join(@RequestParam("venueId") Integer venueId) {
        return ResponseDTO.ok().addAttribute("flg", venueService.join(getMemberIdByAccessToken(), venueId));
    }


}
