package com.djhk.uav.airspace.service.impl;


import com.djhk.uav.airspace.domain.AirspaceApply;
import com.djhk.uav.airspace.domain.AirspaceWaypoint;
import com.djhk.uav.airspace.mapper.AirspaceMapper;
import com.djhk.uav.airspace.service.AirspaceService;
import com.djhk.uav.airspace.service.AirspaceWaypointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class AirspaceImpl implements AirspaceService {

    @Resource
    private AirspaceMapper airspaceMapper;
    @Autowired
    private AirspaceWaypointService airspaceWaypointService;


    @Override
    public AirspaceApply selectAirspaceApplyById(Long id) {
        return airspaceMapper.selectAirspaceApplyById(id);
    }

    @Override
    public Long selectAirspaceApplyId() {
        return airspaceMapper.selectAirspaceApplyId();
    }


    @Override
    public List<AirspaceApply> selectAirspaceApplyList(AirspaceApply airspaceApply) {
        List<AirspaceApply> airspaceApplys = new ArrayList<>();
        List<AirspaceApply> airspaceApplyList = airspaceMapper.selectAirspaceApplyList(airspaceApply);
        for (AirspaceApply apply : airspaceApplyList) {
            List<AirspaceWaypoint> airspaceWaypoints = airspaceWaypointService.selectAirspaceWaypointList(apply.getId());
            apply.setAirlineWaypointList(airspaceWaypoints);
            airspaceApplys.add(apply);
        }
        return airspaceApplys;
    }

    @Override
    public int insertAirspaceApply(AirspaceApply airspaceApply) {
        return airspaceMapper.insertAirspaceApply(airspaceApply);
    }

    @Override
    public int updateAirspaceApply(AirspaceApply airspaceApply) {
        return airspaceMapper.updateAirspaceApply(airspaceApply);
    }

    @Override
    public int deleteAirspaceApplyById(Long id) {
        return airspaceMapper.deleteAirspaceApplyById(id);
    }

    @Override
    public int deleteAirspaceApplyByIds(Long[] ids) {
        return airspaceMapper.deleteAirspaceApplyByIds(ids);
    }
}
