package com.hdkj.lt.si.controller.svg;

import com.hdkj.lt.feign.ILineSvgFileApiClient;
import com.hdkj.lt.feign.ISvgGenerationApiClient;
import com.hdkj.lt.modle.dto.file.LineSvgFileBase;
import com.hdkj.lt.modle.dto.file.LineSvgFileGetDTO;
import com.hdkj.lt.modle.dto.svg.DynamicSvgDTO;
import com.hdkj.lt.modle.dto.svg.DynamicSvgDetailDTO;
import com.hdkj.lt.modle.dto.svg.StationSvgGenerationDTO;
import com.hdkj.lt.modle.dto.svg.SvgGenerationDTO;
import com.hdkj.lt.modle.vo.svg.DynamicSvgVO;
import com.hdkj.lt.modle.vo.svg.LineFileInfoVO;
import com.hdkj.lt.modle.vo.svg.StationFileInfoVO;
import com.hdkj.lt.si.modle.LineSvgQuery;
import com.hdkj.lt.si.service.svg.ICityFeederTopoService;
import com.hdkj.lt.si.service.svg.ISvgGenerationService;
import com.hdkj.hussar.ApiResponse;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @Description
 * @Author wcx
 * @Date 2025/6/30 20:49
 * @Version 1.0
 */
@RestController
@RequiredArgsConstructor
public class SvgFileController {

    private final ILineSvgFileApiClient lineSvgFileApiClient;
    private final ISvgGenerationApiClient svgGenerationApiClient;
    private final ISvgGenerationService svgGenerationService;
    private final ICityFeederTopoService cityFeederTopoService;

    @PostMapping("getLine")
    public ApiResponse<List<LineSvgFileGetDTO>> getLineByVersion(@Valid @RequestBody LineSvgFileBase lineSvgFile) {
        return lineSvgFileApiClient.getLineByVersion(lineSvgFile);
    }

    @PostMapping("getLineSvg")
    public ApiResponse<String> getLineFileInfo(@Valid @RequestBody LineSvgFileGetDTO lineSvgFile) {
        String data = new String(lineSvgFileApiClient.getLineFileInfo(lineSvgFile).getData(), StandardCharsets.UTF_8);
        return ApiResponse.success(data);
    }

    @PostMapping("saveDynamicSvg")
    public ApiResponse<List<LineFileInfoVO>> lineDynamicSvgSave(@Valid @RequestBody SvgGenerationDTO svgGeneration) {
        return lineSvgFileApiClient.lineDynamicSvgSave(svgGeneration);
    }

    @PostMapping("saveStationDynamicSvg")
    public ApiResponse<List<StationFileInfoVO>> stationSvgFileSave(@Valid @RequestBody StationSvgGenerationDTO stationSvgDTO) {
        return lineSvgFileApiClient.stationDynamicSvgSave(stationSvgDTO);
    }

    @PostMapping("/dealCityFeederTopo")
    @ApiOperation(value = "线路topo结构数据分析", notes = "线路topo结构数据分析")
    public ApiResponse<Boolean> dealCityFeederTopo(@RequestBody List<String> cityIds) {
        return ApiResponse.success(cityFeederTopoService.dealCityFeederTopo(cityIds));
    }

    @PostMapping("allLineSvgSave")
    public ApiResponse<String> allLineSvgFileSave(@Valid @RequestBody LineSvgQuery lineSvgQuery) {
        return svgGenerationService.allLineSvgFileSave(lineSvgQuery.getCityShort());
    }

    @PostMapping("nonLineSceneSvgSave")
    public ApiResponse<String> nonLineSceneSvgFileSave(@Valid @RequestBody LineSvgQuery lineSvgQuery) {
        return svgGenerationService.nonLineSceneSvgFileSave(lineSvgQuery.getCityShort());
    }

    @PostMapping("lineSvgReset")
    public ApiResponse<String> lineSvgReset() {
        return svgGenerationService.lineSvgReset();
    }

    @PostMapping("free/ct/getXlYjll")
    public ApiResponse<DynamicSvgVO> queryDynamicSvg(@RequestBody DynamicSvgDTO dynamicSvgDTO) {
        return svgGenerationApiClient.queryDynamicSvg(dynamicSvgDTO);
    }

    @PostMapping("free/ct/getXlYjllXt")
    public ApiResponse<DynamicSvgVO> queryDynamicSvgDetail(DynamicSvgDetailDTO dynamicSvgDetailDTO) {
        return svgGenerationApiClient.queryDynamicSvgDetail(dynamicSvgDetailDTO);
    }

}
