// 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.

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

  extension Clients {
    protocol SqlUsersServiceStub {
      func delete(
        request: SqlUsersDeleteRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudSqlV1.Operation

      func `get`(
        request: SqlUsersGetRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudSqlV1.User

      func insert(
        request: SqlUsersInsertRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudSqlV1.Operation

      func list(
        request: SqlUsersListRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudSqlV1.UsersListResponse

      func update(
        request: SqlUsersUpdateRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudSqlV1.Operation
    }

    class SqlUsersServiceTransport: SqlUsersServiceStub {
      let inner: GoogleCloudGax.HTTPClient

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

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

      public func `get`(
        request: SqlUsersGetRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudSqlV1.User {
        let path = try { () throws -> Swift.String in
          guard let pathVariable0 = request.project as Swift.String?, !pathVariable0.isEmpty else {
            throw GoogleCloudGax.RequestError.binding("'request.project' is not set or is empty")
          }
          guard let pathVariable1 = request.instance as Swift.String?, !pathVariable1.isEmpty else {
            throw GoogleCloudGax.RequestError.binding("'request.instance' is not set or is empty")
          }
          guard let pathVariable2 = request.name as Swift.String?, !pathVariable2.isEmpty else {
            throw GoogleCloudGax.RequestError.binding("'request.name' is not set or is empty")
          }
          return "/v1/projects/\(pathVariable0)/instances/\(pathVariable1)/users/\(pathVariable2)"
        }()
        var query = [
          URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
        ]
        let encoder = GoogleCloudGax.QueryParameterEncoder()
        query.append(contentsOf: try encoder.encode(request.host, prefix: "host"))
        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(
          GoogleCloudSqlV1.User.self, from: data)
      }

      public func insert(
        request: SqlUsersInsertRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudSqlV1.Operation {
        let path = try { () throws -> Swift.String in
          guard let pathVariable0 = request.project as Swift.String?, !pathVariable0.isEmpty else {
            throw GoogleCloudGax.RequestError.binding("'request.project' is not set or is empty")
          }
          guard let pathVariable1 = request.instance as Swift.String?, !pathVariable1.isEmpty else {
            throw GoogleCloudGax.RequestError.binding("'request.instance' is not set or is empty")
          }
          return "/v1/projects/\(pathVariable0)/instances/\(pathVariable1)/users"
        }()
        let query = [
          URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
        ]
        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.body {
          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(
          GoogleCloudSqlV1.Operation.self, from: data)
      }

      public func list(
        request: SqlUsersListRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudSqlV1.UsersListResponse {
        let path = try { () throws -> Swift.String in
          guard let pathVariable0 = request.project as Swift.String?, !pathVariable0.isEmpty else {
            throw GoogleCloudGax.RequestError.binding("'request.project' is not set or is empty")
          }
          guard let pathVariable1 = request.instance as Swift.String?, !pathVariable1.isEmpty else {
            throw GoogleCloudGax.RequestError.binding("'request.instance' is not set or is empty")
          }
          return "/v1/projects/\(pathVariable0)/instances/\(pathVariable1)/users"
        }()
        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(
          GoogleCloudSqlV1.UsersListResponse.self, from: data)
      }

      public func update(
        request: SqlUsersUpdateRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudSqlV1.Operation {
        let path = try { () throws -> Swift.String in
          guard let pathVariable0 = request.project as Swift.String?, !pathVariable0.isEmpty else {
            throw GoogleCloudGax.RequestError.binding("'request.project' is not set or is empty")
          }
          guard let pathVariable1 = request.instance as Swift.String?, !pathVariable1.isEmpty else {
            throw GoogleCloudGax.RequestError.binding("'request.instance' is not set or is empty")
          }
          return "/v1/projects/\(pathVariable0)/instances/\(pathVariable1)/users"
        }()
        var query = [
          URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
        ]
        let encoder = GoogleCloudGax.QueryParameterEncoder()
        query.append(contentsOf: try encoder.encode(request.host, prefix: "host"))
        query.append(contentsOf: try encoder.encode(request.name, prefix: "name"))
        query.append(contentsOf: try encoder.encode(request.databaseRoles, prefix: "databaseRoles"))
        query.append(
          contentsOf: try encoder.encode(request.revokeExistingRoles, prefix: "revokeExistingRoles")
        )
        query.append(contentsOf: try encoder.encode(request.serverRoles, prefix: "serverRoles"))
        query.append(
          contentsOf: try encoder.encode(
            request.revokeExistingServerRoles, prefix: "revokeExistingServerRoles"))
        var req = try await self.inner.Request(path: path, query: query)
        req.httpMethod = "PUT"
        req.setValue(Clients.clientHeader, forHTTPHeaderField: "X-Goog-Api-Client")
        if let body = request.body {
          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(
          GoogleCloudSqlV1.Operation.self, from: data)
      }
    }
  }
#endif
