package com.tuoheng.admin.tzhl.service.airportline;


import com.alibaba.fastjson.JSON;
import com.tuoheng.admin.tzhl.constant.TZHLConstant;
import com.tuoheng.admin.tzhl.request.TZHLGetAirportLineListRequest;
import com.tuoheng.admin.tzhl.response.TZHLAirportLineResponse;
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author ChengWang
 * @Date 2023/8/9
 */
@Service
@Slf4j
public class TZHLGetAirportLineListService {

    @Autowired
    private CallTianYiPlatformService callTianYiPlatformService;

    public JsonResult getAirportLine(String name, String sn, Long id, String lineType) {
        TZHLGetAirportLineListRequest request = new TZHLGetAirportLineListRequest();
        request.setName(name);
        request.setSn(sn);
        request.setId(id);
        request.setLineType(lineType);
        //获取航线列表
        String url = TZHLConstant.TIAN_YI_API_FLY_LINE_LIST;


        String data = callTianYiPlatformService.callPost(url, request);

        List<TZHLAirportLineResponse> tzhlAirportLineResponses = JSON.parseArray(data, TZHLAirportLineResponse.class);


        return JsonResult.success(tzhlAirportLineResponses);
    }

    public TZHLAirportLineResponse getAirportLineById(Long id) {
        TZHLGetAirportLineListRequest request = new TZHLGetAirportLineListRequest();
        request.setId(id);
        //获取航线列表
        String url = TZHLConstant.TIAN_YI_API_FLY_LINE_LIST;
        String data = callTianYiPlatformService.callPost(url, request);
        List<TZHLAirportLineResponse> tzhlAirportLineResponseList = JSON.parseArray(data, TZHLAirportLineResponse.class);
        for (TZHLAirportLineResponse tzhlAirportLineResponse : tzhlAirportLineResponseList) {
            if (id.equals(tzhlAirportLineResponse.getId())) {
                return tzhlAirportLineResponse;
            }
        }
        return null;
    }

}
