package cn.reghao.tnb.content.app.geo.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.common.db.SelectOption;
import cn.reghao.tnb.content.api.dto.geo.MallReplyDto;
import cn.reghao.tnb.content.app.geo.model.vo.MapMarker;
import cn.reghao.tnb.content.app.geo.model.vo.MarkerInfo;
import cn.reghao.tnb.content.app.geo.service.PhotoMapService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2023-08-31 10:32:28
 */
@Tag(name = "照片地图接口")
@RestController
@RequestMapping("/api/geo/photo")
public class PhotoMapController {
    private final PhotoMapService photoMapService;

    public PhotoMapController(PhotoMapService photoMapService) {
        this.photoMapService = photoMapService;
    }

    @Operation(summary = "添加淘宝商品评论", description = "N")
    @PostMapping(value = "/reply", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addReply(@RequestBody @Validated MallReplyDto mallReplyDto) {
        photoMapService.addTmallReply(mallReplyDto);
        return WebResult.success();
    }

    @Operation(summary = "获取照片分类", description = "N")
    @GetMapping(value = "/item", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getGeoItems() {
        List<SelectOption> selectOptions = photoMapService.getGeoItems();
        return WebResult.success(selectOptions);
    }

    @Operation(summary = "获取照片地图中标记", description = "N")
    @GetMapping(value = "/marks", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getPhotoMarks(@RequestParam("type") Integer type) {
        List<MapMarker> list = photoMapService.getPhotoMarks(type);
        return WebResult.success(list);
    }

    @Operation(summary = "获取照片地图中标记", description = "N")
    @GetMapping(value = "/marks_area", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getPhotoMarksArea(@RequestParam("areaCode") int areaCode) {
        List<MapMarker> list = photoMapService.getPhotoMarksArea(areaCode);
        return WebResult.success(list);
    }

    @Operation(summary = "获取我附近的地图标记", description = "N")
    @GetMapping(value = "/marks_nearby", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getMapDistance(@RequestParam("distance") int distance) {
        List<MapMarker> list = photoMapService.getMapDistance(distance);
        return WebResult.success(list);
    }

    @AuthUser
    @Operation(summary = "获取地图中标记点的详情", description = "N")
    @GetMapping(value = "/mark/info", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getMarkerInfo(@RequestParam("id") int id) {
        MarkerInfo markerInfo = photoMapService.getMarkerInfo(id);
        return WebResult.success(markerInfo);
    }
}
