package com.conveyal.taui.models;

import java.util.BitSet;
import java.util.List;

import com.conveyal.geojson.GeometryDeserializer;
import com.conveyal.geojson.GeometrySerializer;
import com.conveyal.r5.model.json_serialization.BitSetDeserializer;
import com.conveyal.r5.model.json_serialization.BitSetSerializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.vividsolutions.jts.geom.LineString;

/**
 * Add a trip pattern.
 */
public class AddTripPattern extends Modification {
    public String name;

    @JsonDeserialize(using= GeometryDeserializer.class)
    @JsonSerialize(using= GeometrySerializer.class)
    public LineString geometry;
    // in theory these would be more efficient as bitsets but they'd get turned into
    // boolean[] when sent to mongo
    public boolean[] stops;
    public boolean[] controlPoints;

    /** stop IDs that particular points have been snapped to. will be mostly null, as most stops are generally not snapped */
    public String[] stopIds;

    public boolean bidirectional;

    public List<Timetable> timetables;

    public String getType() {
        return "add-trip-pattern";
    }

    public static class Timetable {
        /** Days of the week on which this service is active, 0 is Monday */
        @JsonDeserialize(using = BitSetDeserializer.class)
        @JsonSerialize(using = BitSetSerializer.class)
        public BitSet days;

        /** Speed, kilometers per hour */
        public int speed;

        /** hop times in seconds */
        public int[] hopTimes;

        /** dwell times in seconds */
        public int[] dwellTimes;

        /** is this a frequency entry? */
        public boolean frequency;

        /** start time (seconds since GTFS midnight) */
        public int startTime;

        /** end time for frequency-based trips (seconds since GTFS midnight) */
        public int endTime;

        /** Dwell time at each stop, seconds */
        public int dwellTime;

        /** headway for frequency-based patterns */
        public int headwaySecs;
    }
}

@@ -1323,165 +1323,97 @@
 tive
-, 0 is Monday */%0A        @JsonDeserialize(using = BitSetDeserializer.class)%0A        @JsonSerialize(using = BitSetSerializer.class)%0A        public BitSet 
+ */%0A        public boolean monday, tuesday, wednesday, thursday, friday, saturday, sun
 day
-s
 ;%0A%0A 
@@ -1578,32 +1578,32 @@
 s in seconds */%0A
+
         public i
@@ -1624,85 +1624,8 @@
 s;%0A%0A
-        /** is this a frequency entry? */%0A        public boolean frequency;%0A%0A
     

switch to named fields for days of the week.