package org.opentripplanner.standalone;

import java.util.List;

import org.onebusaway.gtfs.model.AgencyAndId;
import org.onebusaway.gtfs.model.Stop;
import org.onebusaway.gtfs.model.Trip;

import com.beust.jcommander.internal.Lists;

public class TripTimeShort {
    
    public static final int UNDEFINED = -1;
    public AgencyAndId stopId;
    public int scheduledArrival = UNDEFINED;
    public int scheduledDeparture = UNDEFINED;
    public int realtimeArrival = UNDEFINED;
    public int realtimeDeparture = UNDEFINED;
    public int arrivalDelay = UNDEFINED;
    public int departureDelay = UNDEFINED;
    public boolean timepoint = false;
    
    /**
     * This is stop-specific, so the index i is a stop index, not a hop index.
     */
    public TripTimeShort(TripTimes tt, int i, Stop stop) {
        this.stopId = stop.getId();
        this.scheduledArrival = tt.getScheduledArrivalTime(i);
        this.realtimeArrival = tt.getArrivalTime(i);
        this.arrivalDelay = tt.getArrivalDelay(i);
        this.scheduledDeparture = tt.getScheduledDepartureTime(i);
        this.realtimeDeparture = tt.getDepartureTime(i);
        this.departureDelay = tt.getDepartureDelay(i);
        this.timepoint = tt.isTimepoint(i);
    }
    
    /**
     * must pass in both table and trip, because tripTimes do not have stops.
     */
    public static List<TripTimeShort> fromTripTimes(Timetable table, Trip trip) {
        TripTimes times = table.getTripTimes(table.getTripIndex(trip.getId()));
        List<TripTimeShort> out = Lists.newArrayList();
        // one per stop, not one per hop, thus the <= operator
        for (int i = 0; i < times.getNumStops(); ++i) {
            out.add(new TripTimeShort(times, i, table.pattern.getStop(i)));
        }
        return out;
    }

}