// Code generated by sidekick. DO NOT EDIT.
//
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation
#if canImport(FoundationNetworking)
  import FoundationNetworking
#endif
import GoogleCloudWkt
import GoogleCloudGax

extension Clients {
  protocol ServiceMonitoringServiceStub {
    func createService(
      request: CreateServiceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.Service

    func getService(
      request: GetServiceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.Service

    func listServices(
      request: ListServicesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ListServicesResponse

    func updateService(
      request: UpdateServiceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.Service

    func deleteService(
      request: DeleteServiceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws

    func createServiceLevelObjective(
      request: CreateServiceLevelObjectiveRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ServiceLevelObjective

    func getServiceLevelObjective(
      request: GetServiceLevelObjectiveRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ServiceLevelObjective

    func listServiceLevelObjectives(
      request: ListServiceLevelObjectivesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ListServiceLevelObjectivesResponse

    func updateServiceLevelObjective(
      request: UpdateServiceLevelObjectiveRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ServiceLevelObjective

    func deleteServiceLevelObjective(
      request: DeleteServiceLevelObjectiveRequest, options: GoogleCloudGax.RequestOptions
    ) async throws
  }

  class ServiceMonitoringServiceTransport: ServiceMonitoringServiceStub {
    let inner: GoogleCloudGax.HTTPClient

    public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
      self.inner = try GoogleCloudGax.HTTPClient(
        from: options, withDefaultEndpoint: "https://monitoring.googleapis.com")
    }

    public func createService(
      request: CreateServiceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.Service {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.parent as Swift.String?, !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.parent' is not set or is empty")
        }
        return "/v3/\(pathVariable0)/services"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      query.append(contentsOf: try encoder.encode(request.serviceId, prefix: "serviceId"))
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "POST"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      if let body = request.service {
        req.setValue("application/json", forHTTPHeaderField: "Content-Type")
        req.httpBody = try JSONEncoder().encode(body)
      }
      let (data, _) = try await self.inner.rpc(for: req).get()
      return try GoogleCloudWkt._ProtoJSONDecoder().decode(
        GoogleCloudMonitoringV3.Service.self, from: data)
    }

    public func getService(
      request: GetServiceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.Service {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.name as Swift.String?, !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.name' is not set or is empty")
        }
        return "/v3/\(pathVariable0)"
      }()
      let query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "GET"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      let (data, _) = try await self.inner.rpc(for: req).get()
      return try GoogleCloudWkt._ProtoJSONDecoder().decode(
        GoogleCloudMonitoringV3.Service.self, from: data)
    }

    public func listServices(
      request: ListServicesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ListServicesResponse {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.parent as Swift.String?, !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.parent' is not set or is empty")
        }
        return "/v3/\(pathVariable0)/services"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      query.append(contentsOf: try encoder.encode(request.filter, prefix: "filter"))
      query.append(contentsOf: try encoder.encode(request.pageSize, prefix: "pageSize"))
      query.append(contentsOf: try encoder.encode(request.pageToken, prefix: "pageToken"))
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "GET"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      let (data, _) = try await self.inner.rpc(for: req).get()
      return try GoogleCloudWkt._ProtoJSONDecoder().decode(
        GoogleCloudMonitoringV3.ListServicesResponse.self, from: data)
    }

    public func updateService(
      request: UpdateServiceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.Service {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.service.map({ $0.name }), !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.service.name' is not set or is empty")
        }
        return "/v3/\(pathVariable0)"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      query.append(contentsOf: try encoder.encode(request.updateMask, prefix: "updateMask"))
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "PATCH"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      if let body = request.service {
        req.setValue("application/json", forHTTPHeaderField: "Content-Type")
        req.httpBody = try JSONEncoder().encode(body)
      }
      let (data, _) = try await self.inner.rpc(for: req).get()
      return try GoogleCloudWkt._ProtoJSONDecoder().decode(
        GoogleCloudMonitoringV3.Service.self, from: data)
    }

    public func deleteService(
      request: DeleteServiceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.name as Swift.String?, !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.name' is not set or is empty")
        }
        return "/v3/\(pathVariable0)"
      }()
      let query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "DELETE"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      _ = try await self.inner.rpc(for: req).get()
    }

    public func createServiceLevelObjective(
      request: CreateServiceLevelObjectiveRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ServiceLevelObjective {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.parent as Swift.String?, !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.parent' is not set or is empty")
        }
        return "/v3/\(pathVariable0)/serviceLevelObjectives"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      query.append(
        contentsOf: try encoder.encode(
          request.serviceLevelObjectiveId, prefix: "serviceLevelObjectiveId"))
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "POST"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      if let body = request.serviceLevelObjective {
        req.setValue("application/json", forHTTPHeaderField: "Content-Type")
        req.httpBody = try JSONEncoder().encode(body)
      }
      let (data, _) = try await self.inner.rpc(for: req).get()
      return try GoogleCloudWkt._ProtoJSONDecoder().decode(
        GoogleCloudMonitoringV3.ServiceLevelObjective.self, from: data)
    }

    public func getServiceLevelObjective(
      request: GetServiceLevelObjectiveRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ServiceLevelObjective {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.name as Swift.String?, !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.name' is not set or is empty")
        }
        return "/v3/\(pathVariable0)"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      query.append(contentsOf: try encoder.encode(request.view, prefix: "view"))
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "GET"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      let (data, _) = try await self.inner.rpc(for: req).get()
      return try GoogleCloudWkt._ProtoJSONDecoder().decode(
        GoogleCloudMonitoringV3.ServiceLevelObjective.self, from: data)
    }

    public func listServiceLevelObjectives(
      request: ListServiceLevelObjectivesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ListServiceLevelObjectivesResponse {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.parent as Swift.String?, !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.parent' is not set or is empty")
        }
        return "/v3/\(pathVariable0)/serviceLevelObjectives"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      query.append(contentsOf: try encoder.encode(request.filter, prefix: "filter"))
      query.append(contentsOf: try encoder.encode(request.pageSize, prefix: "pageSize"))
      query.append(contentsOf: try encoder.encode(request.pageToken, prefix: "pageToken"))
      query.append(contentsOf: try encoder.encode(request.view, prefix: "view"))
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "GET"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      let (data, _) = try await self.inner.rpc(for: req).get()
      return try GoogleCloudWkt._ProtoJSONDecoder().decode(
        GoogleCloudMonitoringV3.ListServiceLevelObjectivesResponse.self, from: data)
    }

    public func updateServiceLevelObjective(
      request: UpdateServiceLevelObjectiveRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.ServiceLevelObjective {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.serviceLevelObjective.map({ $0.name }),
          !pathVariable0.isEmpty
        else {
          throw GoogleCloudGax.RequestError.binding(
            "'request.service_level_objective.name' is not set or is empty")
        }
        return "/v3/\(pathVariable0)"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      query.append(contentsOf: try encoder.encode(request.updateMask, prefix: "updateMask"))
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "PATCH"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      if let body = request.serviceLevelObjective {
        req.setValue("application/json", forHTTPHeaderField: "Content-Type")
        req.httpBody = try JSONEncoder().encode(body)
      }
      let (data, _) = try await self.inner.rpc(for: req).get()
      return try GoogleCloudWkt._ProtoJSONDecoder().decode(
        GoogleCloudMonitoringV3.ServiceLevelObjective.self, from: data)
    }

    public func deleteServiceLevelObjective(
      request: DeleteServiceLevelObjectiveRequest, options: GoogleCloudGax.RequestOptions
    ) async throws {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.name as Swift.String?, !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.name' is not set or is empty")
        }
        return "/v3/\(pathVariable0)"
      }()
      let query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      var req = try await self.inner.Request(path: path, query: query)
      req.httpMethod = "DELETE"
      req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
      _ = try await self.inner.rpc(for: req).get()
    }
  }
}
