});
// List all states
Flight::route('/v1/states/', function () {
    Flight::render('states.php');
});
// List cities from a certain state
Flight::route('GET /v1/states/@state/cities', function ($state) {
    $state = strtoupper($state);
    $json_states = get_states('cities.csv', $state);
    Flight::json($json_states);
});
// Lists a single city, can receive radius query data
Flight::route('GET /v1/states/@state/cities/@city', function ($state, $city) {
    $state = strtoupper($state);
    if (is_numeric($city)) {
        $current_city = find_city_by_id('cities.csv', $city);
    } else {
        $current_city = find_city_by_name('cities.csv', $city, $state);
    }
    if (isset($current_city)) {
        $cityname = $current_city->name;
        $radius = Flight::request()->query->radius;
        $nearby = find_distance($state, $cityname, $radius, 'cities.csv');
        Flight::json($nearby);
    }
});
// Allow users to mark visits to a city
Flight::route('POST /v1/users/@user/visits', function ($user) {
    $city = Flight::request()->data->name;
    $state = Flight::request()->data->state;
    $current_city = find_city_by_name('cities.csv', $city, $state);
function visited_cities($visitfile, $cityfile, $user_id)
{
    $visits = json_decode(add_headers_to_json($visitfile));
    $visited_cities = array();
    foreach ($visits as $visit) {
        $visit_user_id = $visit->user_id;
        if ($visit_user_id == $user_id) {
            $visited_city_id = $visit->city_id;
            $visited_city = find_city_by_id($cityfile, $visited_city_id);
            $visited_cities[] = $visited_city;
        }
    }
    if (count($visited_cities) > 0) {
        echo '<h3>Your Visited Cities:</h3>';
        foreach ($visited_cities as $visited_city) {
            echo $visited_city->name . ", " . $visited_city->state . "<br>";
        }
        return $visited_cities;
    } else {
        echo 'It looks like you haven\'t visited any cities yet!';
    }
}