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.content.app.geo.model.vo.CascadeOption;
import cn.reghao.tnb.content.app.geo.model.vo.MapMarker;
import cn.reghao.tnb.content.app.geo.model.vo.MapPoint;
import cn.reghao.tnb.content.app.geo.service.MapService;
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/map")
public class MapController {
    private final MapService mapService;
    private final PhotoMapService photoMapService;

    public MapController(MapService mapService, PhotoMapService photoMapService) {
        this.mapService = mapService;
        this.photoMapService = photoMapService;
    }

    @AuthUser
    @Operation(summary = "添加一个经纬度坐标", description = "N")
    @PostMapping(value = "/position", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addGeoPoint(@RequestBody @Validated MapPoint mapPoint) {
        mapService.addGeoPoint(mapPoint);
        return WebResult.success();
    }

    @AuthUser
    @Operation(summary = "设置我的位置", description = "N")
    @PostMapping(value = "/my_position", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addMyPoint(@RequestBody @Validated MapPoint mapPoint) {
        mapService.setMyPosition(mapPoint);
        return WebResult.success();
    }

    @AuthUser
    @Operation(summary = "添加地图上的路径", description = "N")
    @PostMapping(value = "/trail", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addTrail(@RequestBody @Validated List<MapPoint> list) {
        mapService.addTrail(list);
        return WebResult.success();
    }

    @AuthUser
    @Operation(summary = "获取坐标列表构成的路径", description = "N")
    @GetMapping(value = "/trail/{trailId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getTrail(@PathVariable("trailId") long trailId) {
        List list = mapService.getTrailPath();
        return WebResult.success(list);
    }

    @AuthUser
    @Operation(summary = "获取地图标记", description = "N")
    @GetMapping(value = "/marks", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getTrailMarks() {
        List<MapMarker> list = mapService.getTrailMarks();
        //List<MapMarker> list = mapService.getStationMarks().subList(0, 1000);
        return WebResult.success(list);
    }

    @Operation(summary = "获取地图标记", description = "N")
    @GetMapping(value = "/cup", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getCupMap() {
        List<MapMarker> list = photoMapService.getPhotoMarks(4);
        return WebResult.success(list);
    }

    @Operation(summary = "省市县三级联动列表", description = "N")
    @GetMapping(value = "/cascade", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getCascadeOptions() {
        List<CascadeOption> list = mapService.getChinaCascade();
        return WebResult.success(list);
    }
}
