// 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 OrgPolicyStub {
    func listConstraints(
      request: ListConstraintsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.ListConstraintsResponse

    func listPolicies(
      request: ListPoliciesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.ListPoliciesResponse

    func getPolicy(
      request: GetPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.Policy

    func getEffectivePolicy(
      request: GetEffectivePolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.Policy

    func createPolicy(
      request: CreatePolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.Policy

    func updatePolicy(
      request: UpdatePolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.Policy

    func deletePolicy(
      request: DeletePolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws

    func createCustomConstraint(
      request: CreateCustomConstraintRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.CustomConstraint

    func updateCustomConstraint(
      request: UpdateCustomConstraintRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.CustomConstraint

    func getCustomConstraint(
      request: GetCustomConstraintRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.CustomConstraint

    func listCustomConstraints(
      request: ListCustomConstraintsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.ListCustomConstraintsResponse

    func deleteCustomConstraint(
      request: DeleteCustomConstraintRequest, options: GoogleCloudGax.RequestOptions
    ) async throws
  }

  class OrgPolicyTransport: OrgPolicyStub {
    let inner: GoogleCloudGax.HTTPClient

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

    public func listConstraints(
      request: ListConstraintsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.ListConstraintsResponse {
      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 "/v2/\(pathVariable0)/constraints"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      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(
        GoogleCloudOrgPolicyV2.ListConstraintsResponse.self, from: data)
    }

    public func listPolicies(
      request: ListPoliciesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.ListPoliciesResponse {
      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 "/v2/\(pathVariable0)/policies"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      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(
        GoogleCloudOrgPolicyV2.ListPoliciesResponse.self, from: data)
    }

    public func getPolicy(
      request: GetPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.Policy {
      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 "/v2/\(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(
        GoogleCloudOrgPolicyV2.Policy.self, from: data)
    }

    public func getEffectivePolicy(
      request: GetEffectivePolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.Policy {
      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 "/v2/\(pathVariable0):getEffectivePolicy"
      }()
      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(
        GoogleCloudOrgPolicyV2.Policy.self, from: data)
    }

    public func createPolicy(
      request: CreatePolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.Policy {
      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 "/v2/\(pathVariable0)/policies"
      }()
      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.policy {
        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(
        GoogleCloudOrgPolicyV2.Policy.self, from: data)
    }

    public func updatePolicy(
      request: UpdatePolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.Policy {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.policy.map({ $0.name }), !pathVariable0.isEmpty else {
          throw GoogleCloudGax.RequestError.binding("'request.policy.name' is not set or is empty")
        }
        return "/v2/\(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.policy {
        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(
        GoogleCloudOrgPolicyV2.Policy.self, from: data)
    }

    public func deletePolicy(
      request: DeletePolicyRequest, 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 "/v2/\(pathVariable0)"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      query.append(contentsOf: try encoder.encode(request.etag, prefix: "etag"))
      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 createCustomConstraint(
      request: CreateCustomConstraintRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.CustomConstraint {
      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 "/v2/\(pathVariable0)/customConstraints"
      }()
      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.customConstraint {
        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(
        GoogleCloudOrgPolicyV2.CustomConstraint.self, from: data)
    }

    public func updateCustomConstraint(
      request: UpdateCustomConstraintRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.CustomConstraint {
      let path = try { () throws -> Swift.String in
        guard let pathVariable0 = request.customConstraint.map({ $0.name }), !pathVariable0.isEmpty
        else {
          throw GoogleCloudGax.RequestError.binding(
            "'request.custom_constraint.name' is not set or is empty")
        }
        return "/v2/\(pathVariable0)"
      }()
      let query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      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.customConstraint {
        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(
        GoogleCloudOrgPolicyV2.CustomConstraint.self, from: data)
    }

    public func getCustomConstraint(
      request: GetCustomConstraintRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.CustomConstraint {
      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 "/v2/\(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(
        GoogleCloudOrgPolicyV2.CustomConstraint.self, from: data)
    }

    public func listCustomConstraints(
      request: ListCustomConstraintsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudOrgPolicyV2.ListCustomConstraintsResponse {
      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 "/v2/\(pathVariable0)/customConstraints"
      }()
      var query = [
        URLQueryItem(name: "$alt", value: "json;enum-encoding=int")
      ]
      let encoder = GoogleCloudGax.QueryParameterEncoder()
      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(
        GoogleCloudOrgPolicyV2.ListCustomConstraintsResponse.self, from: data)
    }

    public func deleteCustomConstraint(
      request: DeleteCustomConstraintRequest, 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 "/v2/\(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()
    }
  }
}
