extend schema
  @link(url: "https://specs.apollo.dev/federation/v2.10", import: ["@tag"])
  @link(
    url: "https://specs.apollo.dev/connect/v0.1"
    import: ["@connect", "@source"]
  )
  @source(
    name: "NWS"
    http: {
      baseURL: "https://api.weather.gov"
      headers: [
        { name: "User-Agent", value: "weather-app/1.0" }
        { name: "Accept", value: "application/geo+json" }
      ]
    }
  )

type Query {
  """
  Get the weather forecast for a coordinate
  """
  forecast(coordinate: InputCoordinate!): Forecast
    @connect(
      source: "NWS"
      http: { GET: "/points/{$args.coordinate.latitude},{$args.coordinate.longitude}" }
      selection: """
      coordinate: {
        latitude: $args.coordinate.latitude
        longitude: $args.coordinate.longitude
      }
      forecastURL: properties.forecast
      """
      entity: true
    )

  """
  Get the weather alerts for a state, using the two-letter abbreviation for the state - for example, CO for Colorado
  """
  alerts(state: String!): [Alert]
    @tag(name: "mcp")
    @connect(
      source: "NWS"
      http: { GET: "/alerts/active/area/{$args.state}" }
      selection: """
      $.features.properties {
        severity
        description
        instruction
      }
      """
    )
}

"""
A weather forecast
"""
type Forecast {
  """
  The coordinate associated with this forecast
  """
  coordinate: Coordinate!

  """
  The National Weather Service (NWS) URL where the forecast data can be read
  """
  forecastURL: String!

  """
  A detailed weather forecast from the National Weather Service (NWS)
  """
  detailed: String!
    @connect(
      http: {
        # GET: "{$this.forecastURL->urlSafe}" # TODO: Use this when urlSafe is implemented
        GET: "https://api.weather.gov/gridpoints/FFC/51,87/forecast" # TODO: remove this hardcoded value
        headers: [
          { name: "foo", value: "{$this.forecastURL}" } # required to make composition not throw a satisfiability error
          { name: "Accept", value: "application/geo+json" }
          { name: "User-Agent", value: "weather-app/1.0" }
        ]
      }
      selection: """
      $.properties.periods->first.detailedForecast
      """
    )
}

"""
A weather alert
"""
type Alert @tag(name: "mcp") {
  """
  The severity of this alert
  """
  severity: String

  """
  A description of the alert
  """
  description: String

  """
  Information about how people should respond to the alert
  """
  instruction: String
}

"""
A coordinate, consisting of a latitude and longitude
"""
input InputCoordinate {
  """
  The latitude of this coordinate
  """
  latitude: String!

  """
  The longitude of this coordinate
  """
  longitude: String!
}


"""
A coordinate, consisting of a latitude and longitude
"""
type Coordinate {
  """
  The latitude of this coordinate
  """
  latitude: String!

  """
  The longitude of this coordinate
  """
  longitude: String!
}