from typing import Any, Dict, List, Literal, Optional, Union
from enum import Enum
from pydantic import BaseModel, Field, ConfigDict

class CaveatEvalInfoResult(str, Enum):
    RESULT_UNSPECIFIED = "RESULT_UNSPECIFIED"
    RESULT_UNEVALUATED = "RESULT_UNEVALUATED"
    RESULT_FALSE = "RESULT_FALSE"
    RESULT_TRUE = "RESULT_TRUE"
    RESULT_MISSING_SOME_CONTEXT = "RESULT_MISSING_SOME_CONTEXT"

class CheckDebugTracePermissionType(str, Enum):
    PERMISSION_TYPE_UNSPECIFIED = "PERMISSION_TYPE_UNSPECIFIED"
    PERMISSION_TYPE_RELATION = "PERMISSION_TYPE_RELATION"
    PERMISSION_TYPE_PERMISSION = "PERMISSION_TYPE_PERMISSION"

class CheckDebugTraceSubProblems(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    traces: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class DeleteRelationshipsResponseDeletionProgress(str, Enum):
    """- DELETION_PROGRESS_COMPLETE: DELETION_PROGRESS_COMPLETE indicates that all remaining relationships matching the filter
were deleted. Will be returned even if no relationships were deleted.
 - DELETION_PROGRESS_PARTIAL: DELETION_PROGRESS_PARTIAL indicates that a subset of the relationships matching the filter
were deleted. Only returned if optional_allow_partial_deletions was true, an optional_limit was
specified, and there existed more relationships matching the filter than optional_limit would allow.
Once all remaining relationships have been deleted, DELETION_PROGRESS_COMPLETE will be returned."""
    DELETION_PROGRESS_UNSPECIFIED = "DELETION_PROGRESS_UNSPECIFIED"
    DELETION_PROGRESS_COMPLETE = "DELETION_PROGRESS_COMPLETE"
    DELETION_PROGRESS_PARTIAL = "DELETION_PROGRESS_PARTIAL"

class LookupSubjectsRequestWildcardOption(str, Enum):
    WILDCARD_OPTION_UNSPECIFIED = "WILDCARD_OPTION_UNSPECIFIED"
    WILDCARD_OPTION_INCLUDE_WILDCARDS = "WILDCARD_OPTION_INCLUDE_WILDCARDS"
    WILDCARD_OPTION_EXCLUDE_WILDCARDS = "WILDCARD_OPTION_EXCLUDE_WILDCARDS"

class SubjectFilterRelationFilter(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    relation: Optional[str] = Field(
        None
    )

class Apiv1Cursor(BaseModel):
    """Cursor is used to provide resumption of listing between calls to APIs
such as LookupResources."""
    model_config = ConfigDict(populate_by_name=True)

    token: Optional[str] = Field(
        None
    )

class ProtobufAny(BaseModel):
    """`Any` contains an arbitrary serialized protocol buffer message along with a
URL that describes the type of the serialized message.

Protobuf library provides support to pack/unpack Any values in the form
of utility functions or additional generated methods of the Any type.

Example 1: Pack and unpack a message in C++.

    Foo foo = ...;
    Any any;
    any.PackFrom(foo);
    ...
    if (any.UnpackTo(&foo)) {
      ...
    }

Example 2: Pack and unpack a message in Java.

    Foo foo = ...;
    Any any = Any.pack(foo);
    ...
    if (any.is(Foo.class)) {
      foo = any.unpack(Foo.class);
    }
    // or ...
    if (any.isSameTypeAs(Foo.getDefaultInstance())) {
      foo = any.unpack(Foo.getDefaultInstance());
    }

 Example 3: Pack and unpack a message in Python.

    foo = Foo(...)
    any = Any()
    any.Pack(foo)
    ...
    if any.Is(Foo.DESCRIPTOR):
      any.Unpack(foo)
      ...

 Example 4: Pack and unpack a message in Go

     foo := &pb.Foo{...}
     any, err := anypb.New(foo)
     if err != nil {
       ...
     }
     ...
     foo := &pb.Foo{}
     if err := any.UnmarshalTo(foo); err != nil {
       ...
     }

The pack methods provided by protobuf library will by default use
'type.googleapis.com/full.type.name' as the type URL and the unpack
methods only use the fully qualified type name after the last '/'
in the type URL, for example "foo.bar.com/x/y.z" will yield type
name "y.z".

JSON
====
The JSON representation of an `Any` value uses the regular
representation of the deserialized, embedded message, with an
additional field `@type` which contains the type URL. Example:

    package google.profile;
    message Person {
      string first_name = 1;
      string last_name = 2;
    }

    {
      "@type": "type.googleapis.com/google.profile.Person",
      "firstName": <string>,
      "lastName": <string>
    }

If the embedded message type is well-known and has a custom JSON
representation, that representation will be embedded adding a field
`value` which holds the custom JSON in addition to the `@type`
field. Example (for message [google.protobuf.Duration][]):

    {
      "@type": "type.googleapis.com/google.protobuf.Duration",
      "value": "1.212s"
    }"""
    model_config = ConfigDict(populate_by_name=True)

    type_: Optional[str] = Field(
        None, alias="@type"
    )

class ProtobufNullValue(str, Enum):
    """`NullValue` is a singleton enumeration to represent the null value for the
`Value` type union.

The JSON representation for `NullValue` is JSON `null`.

 - NULL_VALUE: Null value."""
    NULL_VALUE = "NULL_VALUE"

class RpcStatus(BaseModel):
    """The `Status` type defines a logical error model that is suitable for
different programming environments, including REST APIs and RPC APIs. It is
used by [gRPC](https://github.com/grpc). Each `Status` message contains
three pieces of data: error code, error message, and error details.

You can find out more about this error model and how to work with it in the
[API Design Guide](https://cloud.google.com/apis/design/errors)."""
    model_config = ConfigDict(populate_by_name=True)

    code: Optional[int] = Field(
        None
    )
    message: Optional[str] = Field(
        None
    )
    details: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1AlgebraicSubjectSet(BaseModel):
    """AlgebraicSubjectSet is a subject set which is computed based on applying the
specified operation to the operands according to the algebra of sets.

UNION is a logical set containing the subject members from all operands.

INTERSECTION is a logical set containing only the subject members which are
present in all operands.

EXCLUSION is a logical set containing only the subject members which are
present in the first operand, and none of the other operands."""
    model_config = ConfigDict(populate_by_name=True)

    operation: Optional[Literal["OPERATION_UNSPECIFIED", "OPERATION_UNION", "OPERATION_INTERSECTION", "OPERATION_EXCLUSION"]] = Field(
        None
    )
    children: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1AlgebraicSubjectSetOperation(str, Enum):
    OPERATION_UNSPECIFIED = "OPERATION_UNSPECIFIED"
    OPERATION_UNION = "OPERATION_UNION"
    OPERATION_INTERSECTION = "OPERATION_INTERSECTION"
    OPERATION_EXCLUSION = "OPERATION_EXCLUSION"

class V1BulkCheckPermissionPair(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    request: Optional[Dict[str, Any]] = Field(
        None
    )
    item: Optional[Dict[str, Any]] = Field(
        None
    )
    error: Optional[Dict[str, Any]] = Field(
        None
    )

class V1BulkCheckPermissionRequest(BaseModel):
    """NOTE: Deprecated now that BulkCheckPermission has been promoted to the stable API as "CheckBulkPermission"."""
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    items: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1BulkCheckPermissionRequestItem(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    resource: Optional[Dict[str, Any]] = Field(
        None
    )
    permission: Optional[str] = Field(
        None
    )
    subject: Optional[Dict[str, Any]] = Field(
        None
    )
    context: Optional[Dict[str, Any]] = Field(
        None
    )

class V1BulkCheckPermissionResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    checked_at: Optional[Dict[str, Any]] = Field(
        None, alias="checkedAt"
    )
    pairs: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1BulkCheckPermissionResponseItem(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    permissionship: Optional[Literal["PERMISSIONSHIP_UNSPECIFIED", "PERMISSIONSHIP_NO_PERMISSION", "PERMISSIONSHIP_HAS_PERMISSION", "PERMISSIONSHIP_CONDITIONAL_PERMISSION"]] = Field(
        None
    )
    partial_caveat_info: Optional[Dict[str, Any]] = Field(
        None, alias="partialCaveatInfo"
    )

class V1BulkExportRelationshipsRequest(BaseModel):
    """BulkExportRelationshipsRequest represents a resumable request for
all relationships from the server."""
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    optional_limit: Optional[int] = Field(
        None, alias="optionalLimit"
    )
    optional_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="optionalCursor"
    )
    optional_relationship_filter: Optional[Dict[str, Any]] = Field(
        None, alias="optionalRelationshipFilter"
    )

class V1BulkExportRelationshipsResponse(BaseModel):
    """BulkExportRelationshipsResponse is one page in a stream of relationship
groups that meet the criteria specified by the originating request. The
server will continue to stream back relationship groups as quickly as it can
until all relationships have been transmitted back."""
    model_config = ConfigDict(populate_by_name=True)

    after_result_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="afterResultCursor"
    )
    relationships: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1BulkImportRelationshipsRequest(BaseModel):
    """BulkImportRelationshipsRequest represents one batch of the streaming
BulkImportRelationships API. The maximum size is only limited by the backing
datastore, and optimal size should be determined by the calling client
experimentally. When BulkImport is invoked and receives its first request message,
a transaction is opened to import the relationships. All requests sent to the same
invocation are executed under this single transaction. If a relationship already
exists within the datastore, the entire transaction will fail with an error."""
    model_config = ConfigDict(populate_by_name=True)

    relationships: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1BulkImportRelationshipsResponse(BaseModel):
    """BulkImportRelationshipsResponse is returned on successful completion of the
bulk load stream, and contains the total number of relationships loaded."""
    model_config = ConfigDict(populate_by_name=True)

    num_loaded: Optional[str] = Field(
        None, alias="numLoaded"
    )

class V1CaveatEvalInfo(BaseModel):
    """CaveatEvalInfo holds information about a caveat expression that was evaluated."""
    model_config = ConfigDict(populate_by_name=True)

    expression: Optional[str] = Field(
        None
    )
    result: Optional[Literal["RESULT_UNSPECIFIED", "RESULT_UNEVALUATED", "RESULT_FALSE", "RESULT_TRUE", "RESULT_MISSING_SOME_CONTEXT"]] = Field(
        None
    )
    context: Optional[Dict[str, Any]] = Field(
        None
    )
    partial_caveat_info: Optional[Dict[str, Any]] = Field(
        None, alias="partialCaveatInfo"
    )
    caveat_name: Optional[str] = Field(
        None, alias="caveatName"
    )

class V1CheckBulkPermissionsPair(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    request: Optional[Dict[str, Any]] = Field(
        None
    )
    item: Optional[Dict[str, Any]] = Field(
        None
    )
    error: Optional[Dict[str, Any]] = Field(
        None
    )

class V1CheckBulkPermissionsRequest(BaseModel):
    """CheckBulkPermissionsRequest issues a check on whether a subject has permission
or is a member of a relation on a specific resource for each item in the list.

The ordering of the items in the response is maintained in the response.
Checks with the same subject/permission will automatically be batched for performance optimization."""
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    items: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    with_tracing: Optional[bool] = Field(
        None, alias="withTracing"
    )

class V1CheckBulkPermissionsRequestItem(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    resource: Optional[Dict[str, Any]] = Field(
        None
    )
    permission: Optional[str] = Field(
        None
    )
    subject: Optional[Dict[str, Any]] = Field(
        None
    )
    context: Optional[Dict[str, Any]] = Field(
        None
    )

class V1CheckBulkPermissionsResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    checked_at: Optional[Dict[str, Any]] = Field(
        None, alias="checkedAt"
    )
    pairs: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1CheckBulkPermissionsResponseItem(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    permissionship: Optional[Literal["PERMISSIONSHIP_UNSPECIFIED", "PERMISSIONSHIP_NO_PERMISSION", "PERMISSIONSHIP_HAS_PERMISSION", "PERMISSIONSHIP_CONDITIONAL_PERMISSION"]] = Field(
        None
    )
    partial_caveat_info: Optional[Dict[str, Any]] = Field(
        None, alias="partialCaveatInfo"
    )
    debug_trace: Optional[Dict[str, Any]] = Field(
        None, alias="debugTrace"
    )

class V1CheckDebugTrace(BaseModel):
    """CheckDebugTrace is a recursive trace of the requests made for resolving a CheckPermission
API call."""
    model_config = ConfigDict(populate_by_name=True)

    resource: Optional[Dict[str, Any]] = Field(
        None
    )
    permission: Optional[str] = Field(
        None
    )
    permission_type: Optional[Literal["PERMISSION_TYPE_UNSPECIFIED", "PERMISSION_TYPE_RELATION", "PERMISSION_TYPE_PERMISSION"]] = Field(
        None, alias="permissionType"
    )
    subject: Optional[Dict[str, Any]] = Field(
        None
    )
    result: Optional[Literal["PERMISSIONSHIP_UNSPECIFIED", "PERMISSIONSHIP_NO_PERMISSION", "PERMISSIONSHIP_HAS_PERMISSION", "PERMISSIONSHIP_CONDITIONAL_PERMISSION"]] = Field(
        None
    )
    caveat_evaluation_info: Optional[Dict[str, Any]] = Field(
        None, alias="caveatEvaluationInfo"
    )
    duration: Optional[str] = Field(
        None
    )
    was_cached_result: Optional[bool] = Field(
        None, alias="wasCachedResult"
    )
    sub_problems: Optional[Dict[str, Any]] = Field(
        None, alias="subProblems"
    )
    optional_expires_at: Optional[str] = Field(
        None, alias="optionalExpiresAt"
    )
    trace_operation_id: Optional[str] = Field(
        None, alias="traceOperationId"
    )
    source: Optional[str] = Field(
        None
    )

class V1CheckDebugTracePermissionship(str, Enum):
    PERMISSIONSHIP_UNSPECIFIED = "PERMISSIONSHIP_UNSPECIFIED"
    PERMISSIONSHIP_NO_PERMISSION = "PERMISSIONSHIP_NO_PERMISSION"
    PERMISSIONSHIP_HAS_PERMISSION = "PERMISSIONSHIP_HAS_PERMISSION"
    PERMISSIONSHIP_CONDITIONAL_PERMISSION = "PERMISSIONSHIP_CONDITIONAL_PERMISSION"

class V1CheckPermissionRequest(BaseModel):
    """CheckPermissionRequest issues a check on whether a subject has a permission
or is a member of a relation, on a specific resource."""
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    resource: Optional[Dict[str, Any]] = Field(
        None
    )
    permission: Optional[str] = Field(
        None
    )
    subject: Optional[Dict[str, Any]] = Field(
        None
    )
    context: Optional[Dict[str, Any]] = Field(
        None
    )
    with_tracing: Optional[bool] = Field(
        None, alias="withTracing"
    )

class V1CheckPermissionResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    checked_at: Optional[Dict[str, Any]] = Field(
        None, alias="checkedAt"
    )
    permissionship: Optional[Literal["PERMISSIONSHIP_UNSPECIFIED", "PERMISSIONSHIP_NO_PERMISSION", "PERMISSIONSHIP_HAS_PERMISSION", "PERMISSIONSHIP_CONDITIONAL_PERMISSION"]] = Field(
        None
    )
    partial_caveat_info: Optional[Dict[str, Any]] = Field(
        None, alias="partialCaveatInfo"
    )
    debug_trace: Optional[Dict[str, Any]] = Field(
        None, alias="debugTrace"
    )
    optional_expires_at: Optional[str] = Field(
        None, alias="optionalExpiresAt"
    )

class V1CheckPermissionResponsePermissionship(str, Enum):
    PERMISSIONSHIP_UNSPECIFIED = "PERMISSIONSHIP_UNSPECIFIED"
    PERMISSIONSHIP_NO_PERMISSION = "PERMISSIONSHIP_NO_PERMISSION"
    PERMISSIONSHIP_HAS_PERMISSION = "PERMISSIONSHIP_HAS_PERMISSION"
    PERMISSIONSHIP_CONDITIONAL_PERMISSION = "PERMISSIONSHIP_CONDITIONAL_PERMISSION"

class V1ComputablePermissionsRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    definition_name: Optional[str] = Field(
        None, alias="definitionName"
    )
    relation_name: Optional[str] = Field(
        None, alias="relationName"
    )
    optional_definition_name_filter: Optional[str] = Field(
        None, alias="optionalDefinitionNameFilter"
    )

class V1ComputablePermissionsResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    permissions: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1Consistency(BaseModel):
    """Consistency will define how a request is handled by the backend.
By defining a consistency requirement, and a token at which those
requirements should be applied, where applicable."""
    model_config = ConfigDict(populate_by_name=True)

    minimize_latency: Optional[bool] = Field(
        None, alias="minimizeLatency"
    )
    at_least_as_fresh: Optional[Dict[str, Any]] = Field(
        None, alias="atLeastAsFresh"
    )
    at_exact_snapshot: Optional[Dict[str, Any]] = Field(
        None, alias="atExactSnapshot"
    )
    fully_consistent: Optional[bool] = Field(
        None, alias="fullyConsistent"
    )

class V1ContextualizedCaveat(BaseModel):
    """ContextualizedCaveat represents a reference to a caveat to be used by caveated relationships.
The context consists of key-value pairs that will be injected at evaluation time.
The keys must match the arguments defined on the caveat in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    caveat_name: Optional[str] = Field(
        None, alias="caveatName"
    )
    context: Optional[Dict[str, Any]] = Field(
        None
    )

class V1DebugInformation(BaseModel):
    """DebugInformation defines debug information returned by an API call in a footer when
requested with a specific debugging header.

The specific debug information returned will depend on the type of the API call made.

See the github.com/authzed/authzed-go project for the specific header and footer names."""
    model_config = ConfigDict(populate_by_name=True)

    check: Optional[Dict[str, Any]] = Field(
        None
    )
    schema_used: Optional[str] = Field(
        None, alias="schemaUsed"
    )

class V1DeleteRelationshipsRequest(BaseModel):
    """DeleteRelationshipsRequest specifies which Relationships should be deleted,
requesting the delete of *ALL* relationships that match the specified
filters. If the optional_preconditions parameter is included, all of the
specified preconditions must also be satisfied before the delete will be
executed."""
    model_config = ConfigDict(populate_by_name=True)

    relationship_filter: Optional[Dict[str, Any]] = Field(
        None, alias="relationshipFilter"
    )
    optional_preconditions: Optional[List[Dict[str, Any]]] = Field(
        None, alias="optionalPreconditions"
    )
    optional_limit: Optional[int] = Field(
        None, alias="optionalLimit"
    )
    optional_allow_partial_deletions: Optional[bool] = Field(
        None, alias="optionalAllowPartialDeletions"
    )
    optional_transaction_metadata: Optional[Dict[str, Any]] = Field(
        None, alias="optionalTransactionMetadata"
    )

class V1DeleteRelationshipsResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    deleted_at: Optional[Dict[str, Any]] = Field(
        None, alias="deletedAt"
    )
    deletion_progress: Optional[Literal["DELETION_PROGRESS_UNSPECIFIED", "DELETION_PROGRESS_COMPLETE", "DELETION_PROGRESS_PARTIAL"]] = Field(
        None, alias="deletionProgress"
    )
    relationships_deleted_count: Optional[str] = Field(
        None, alias="relationshipsDeletedCount"
    )

class V1DependentRelationsRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    definition_name: Optional[str] = Field(
        None, alias="definitionName"
    )
    permission_name: Optional[str] = Field(
        None, alias="permissionName"
    )

class V1DependentRelationsResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    relations: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1DiffSchemaRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    comparison_schema: Optional[str] = Field(
        None, alias="comparisonSchema"
    )

class V1DiffSchemaResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    diffs: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1DirectSubjectSet(BaseModel):
    """DirectSubjectSet is a subject set which is simply a collection of subjects."""
    model_config = ConfigDict(populate_by_name=True)

    subjects: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1ExpCaveat(BaseModel):
    """ExpCaveat is the representation of a caveat in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    comment: Optional[str] = Field(
        None
    )
    parameters: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    expression: Optional[str] = Field(
        None
    )

class V1ExpCaveatParameter(BaseModel):
    """ExpCaveatParameter is the representation of a parameter in a caveat."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    type_: Optional[str] = Field(
        None, alias="type"
    )
    parent_caveat_name: Optional[str] = Field(
        None, alias="parentCaveatName"
    )

class V1ExpCaveatParameterTypeChange(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    parameter: Optional[Dict[str, Any]] = Field(
        None
    )
    previous_type: Optional[str] = Field(
        None, alias="previousType"
    )

class V1ExpDefinition(BaseModel):
    """ExpDefinition is the representation of a definition in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    comment: Optional[str] = Field(
        None
    )
    relations: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    permissions: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1ExpPermission(BaseModel):
    """ExpPermission is the representation of a permission in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    comment: Optional[str] = Field(
        None
    )
    parent_definition_name: Optional[str] = Field(
        None, alias="parentDefinitionName"
    )

class V1ExpRelation(BaseModel):
    """ExpRelation is the representation of a relation in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    comment: Optional[str] = Field(
        None
    )
    parent_definition_name: Optional[str] = Field(
        None, alias="parentDefinitionName"
    )
    subject_types: Optional[List[Dict[str, Any]]] = Field(
        None, alias="subjectTypes"
    )

class V1ExpRelationReference(BaseModel):
    """ExpRelationReference is a reference to a relation or permission in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    definition_name: Optional[str] = Field(
        None, alias="definitionName"
    )
    relation_name: Optional[str] = Field(
        None, alias="relationName"
    )
    is_permission: Optional[bool] = Field(
        None, alias="isPermission"
    )

class V1ExpRelationSubjectTypeChange(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    relation: Optional[Dict[str, Any]] = Field(
        None
    )
    changed_subject_type: Optional[Dict[str, Any]] = Field(
        None, alias="changedSubjectType"
    )

class V1ExpSchemaDiff(BaseModel):
    """ExpSchemaDiff is the representation of a diff between two schemas."""
    model_config = ConfigDict(populate_by_name=True)

    definition_added: Optional[Dict[str, Any]] = Field(
        None, alias="definitionAdded"
    )
    definition_removed: Optional[Dict[str, Any]] = Field(
        None, alias="definitionRemoved"
    )
    definition_doc_comment_changed: Optional[Dict[str, Any]] = Field(
        None, alias="definitionDocCommentChanged"
    )
    relation_added: Optional[Dict[str, Any]] = Field(
        None, alias="relationAdded"
    )
    relation_removed: Optional[Dict[str, Any]] = Field(
        None, alias="relationRemoved"
    )
    relation_doc_comment_changed: Optional[Dict[str, Any]] = Field(
        None, alias="relationDocCommentChanged"
    )
    relation_subject_type_added: Optional[Dict[str, Any]] = Field(
        None, alias="relationSubjectTypeAdded"
    )
    relation_subject_type_removed: Optional[Dict[str, Any]] = Field(
        None, alias="relationSubjectTypeRemoved"
    )
    permission_added: Optional[Dict[str, Any]] = Field(
        None, alias="permissionAdded"
    )
    permission_removed: Optional[Dict[str, Any]] = Field(
        None, alias="permissionRemoved"
    )
    permission_doc_comment_changed: Optional[Dict[str, Any]] = Field(
        None, alias="permissionDocCommentChanged"
    )
    permission_expr_changed: Optional[Dict[str, Any]] = Field(
        None, alias="permissionExprChanged"
    )
    caveat_added: Optional[Dict[str, Any]] = Field(
        None, alias="caveatAdded"
    )
    caveat_removed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatRemoved"
    )
    caveat_doc_comment_changed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatDocCommentChanged"
    )
    caveat_expr_changed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatExprChanged"
    )
    caveat_parameter_added: Optional[Dict[str, Any]] = Field(
        None, alias="caveatParameterAdded"
    )
    caveat_parameter_removed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatParameterRemoved"
    )
    caveat_parameter_type_changed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatParameterTypeChanged"
    )

class V1ExpSchemaFilter(BaseModel):
    """ExpSchemaFilter is a filter that can be applied to the schema on reflection."""
    model_config = ConfigDict(populate_by_name=True)

    optional_definition_name_filter: Optional[str] = Field(
        None, alias="optionalDefinitionNameFilter"
    )
    optional_caveat_name_filter: Optional[str] = Field(
        None, alias="optionalCaveatNameFilter"
    )
    optional_relation_name_filter: Optional[str] = Field(
        None, alias="optionalRelationNameFilter"
    )
    optional_permission_name_filter: Optional[str] = Field(
        None, alias="optionalPermissionNameFilter"
    )

class V1ExpTypeReference(BaseModel):
    """ExpTypeReference is the representation of a type reference in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    subject_definition_name: Optional[str] = Field(
        None, alias="subjectDefinitionName"
    )
    optional_caveat_name: Optional[str] = Field(
        None, alias="optionalCaveatName"
    )
    is_terminal_subject: Optional[bool] = Field(
        None, alias="isTerminalSubject"
    )
    optional_relation_name: Optional[str] = Field(
        None, alias="optionalRelationName"
    )
    is_public_wildcard: Optional[bool] = Field(
        None, alias="isPublicWildcard"
    )

class V1ExpandPermissionTreeRequest(BaseModel):
    """ExpandPermissionTreeRequest returns a tree representing the expansion of all
relationships found accessible from a permission or relation on a particular
resource.

ExpandPermissionTreeRequest is typically used to determine the full set of
subjects with a permission, along with the relationships that grant said
access."""
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    resource: Optional[Dict[str, Any]] = Field(
        None
    )
    permission: Optional[str] = Field(
        None
    )

class V1ExpandPermissionTreeResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    expanded_at: Optional[Dict[str, Any]] = Field(
        None, alias="expandedAt"
    )
    tree_root: Optional[Dict[str, Any]] = Field(
        None, alias="treeRoot"
    )

class V1ExperimentalComputablePermissionsRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    definition_name: Optional[str] = Field(
        None, alias="definitionName"
    )
    relation_name: Optional[str] = Field(
        None, alias="relationName"
    )
    optional_definition_name_filter: Optional[str] = Field(
        None, alias="optionalDefinitionNameFilter"
    )

class V1ExperimentalComputablePermissionsResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    permissions: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1ExperimentalCountRelationshipsRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )

class V1ExperimentalCountRelationshipsResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    counter_still_calculating: Optional[bool] = Field(
        None, alias="counterStillCalculating"
    )
    read_counter_value: Optional[Dict[str, Any]] = Field(
        None, alias="readCounterValue"
    )

class V1ExperimentalDependentRelationsRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    definition_name: Optional[str] = Field(
        None, alias="definitionName"
    )
    permission_name: Optional[str] = Field(
        None, alias="permissionName"
    )

class V1ExperimentalDependentRelationsResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    relations: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1ExperimentalDiffSchemaRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    comparison_schema: Optional[str] = Field(
        None, alias="comparisonSchema"
    )

class V1ExperimentalDiffSchemaResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    diffs: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1ExperimentalReflectSchemaRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    optional_filters: Optional[List[Dict[str, Any]]] = Field(
        None, alias="optionalFilters"
    )

class V1ExperimentalReflectSchemaResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    definitions: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    caveats: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1ExperimentalRegisterRelationshipCounterRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    relationship_filter: Optional[Dict[str, Any]] = Field(
        None, alias="relationshipFilter"
    )

class V1ExperimentalRegisterRelationshipCounterResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    pass

class V1ExperimentalUnregisterRelationshipCounterRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )

class V1ExperimentalUnregisterRelationshipCounterResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    pass

class V1ExportBulkRelationshipsRequest(BaseModel):
    """ExportBulkRelationshipsRequest represents a resumable request for
all relationships from the server."""
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    optional_limit: Optional[int] = Field(
        None, alias="optionalLimit"
    )
    optional_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="optionalCursor"
    )
    optional_relationship_filter: Optional[Dict[str, Any]] = Field(
        None, alias="optionalRelationshipFilter"
    )

class V1ExportBulkRelationshipsResponse(BaseModel):
    """ExportBulkRelationshipsResponse is one page in a stream of relationship
groups that meet the criteria specified by the originating request. The
server will continue to stream back relationship groups as quickly as it can
until all relationships have been transmitted back."""
    model_config = ConfigDict(populate_by_name=True)

    after_result_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="afterResultCursor"
    )
    relationships: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1ImportBulkRelationshipsRequest(BaseModel):
    """ImportBulkRelationshipsRequest represents one batch of the streaming
ImportBulkRelationships API. The maximum size is only limited by the backing
datastore, and optimal size should be determined by the calling client
experimentally. When ImportBulk is invoked and receives its first request message,
a transaction is opened to import the relationships. All requests sent to the same
invocation are executed under this single transaction. If a relationship already
exists within the datastore, the entire transaction will fail with an error."""
    model_config = ConfigDict(populate_by_name=True)

    relationships: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1ImportBulkRelationshipsResponse(BaseModel):
    """ImportBulkRelationshipsResponse is returned on successful completion of the
bulk load stream, and contains the total number of relationships loaded."""
    model_config = ConfigDict(populate_by_name=True)

    num_loaded: Optional[str] = Field(
        None, alias="numLoaded"
    )

class V1LookupPermissionship(str, Enum):
    LOOKUP_PERMISSIONSHIP_UNSPECIFIED = "LOOKUP_PERMISSIONSHIP_UNSPECIFIED"
    LOOKUP_PERMISSIONSHIP_HAS_PERMISSION = "LOOKUP_PERMISSIONSHIP_HAS_PERMISSION"
    LOOKUP_PERMISSIONSHIP_CONDITIONAL_PERMISSION = "LOOKUP_PERMISSIONSHIP_CONDITIONAL_PERMISSION"

class V1LookupResourcesRequest(BaseModel):
    """LookupResourcesRequest performs a lookup of all resources of a particular
kind on which the subject has the specified permission or the relation in
which the subject exists, streaming back the IDs of those resources."""
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    resource_object_type: Optional[str] = Field(
        None, alias="resourceObjectType"
    )
    permission: Optional[str] = Field(
        None
    )
    subject: Optional[Dict[str, Any]] = Field(
        None
    )
    context: Optional[Dict[str, Any]] = Field(
        None
    )
    optional_limit: Optional[int] = Field(
        None, alias="optionalLimit"
    )
    optional_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="optionalCursor"
    )

class V1LookupResourcesResponse(BaseModel):
    """LookupResourcesResponse contains a single matching resource object ID for the
requested object type, permission, and subject."""
    model_config = ConfigDict(populate_by_name=True)

    looked_up_at: Optional[Dict[str, Any]] = Field(
        None, alias="lookedUpAt"
    )
    resource_object_id: Optional[str] = Field(
        None, alias="resourceObjectId"
    )
    permissionship: Optional[Literal["LOOKUP_PERMISSIONSHIP_UNSPECIFIED", "LOOKUP_PERMISSIONSHIP_HAS_PERMISSION", "LOOKUP_PERMISSIONSHIP_CONDITIONAL_PERMISSION"]] = Field(
        None
    )
    partial_caveat_info: Optional[Dict[str, Any]] = Field(
        None, alias="partialCaveatInfo"
    )
    after_result_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="afterResultCursor"
    )

class V1LookupSubjectsRequest(BaseModel):
    """LookupSubjectsRequest performs a lookup of all subjects of a particular
kind for which the subject has the specified permission or the relation in
which the subject exists, streaming back the IDs of those subjects."""
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    resource: Optional[Dict[str, Any]] = Field(
        None
    )
    permission: Optional[str] = Field(
        None
    )
    subject_object_type: Optional[str] = Field(
        None, alias="subjectObjectType"
    )
    optional_subject_relation: Optional[str] = Field(
        None, alias="optionalSubjectRelation"
    )
    context: Optional[Dict[str, Any]] = Field(
        None
    )
    optional_concrete_limit: Optional[int] = Field(
        None, alias="optionalConcreteLimit"
    )
    optional_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="optionalCursor"
    )
    wildcard_option: Optional[Literal["WILDCARD_OPTION_UNSPECIFIED", "WILDCARD_OPTION_INCLUDE_WILDCARDS", "WILDCARD_OPTION_EXCLUDE_WILDCARDS"]] = Field(
        None, alias="wildcardOption"
    )

class V1LookupSubjectsResponse(BaseModel):
    """LookupSubjectsResponse contains a single matching subject object ID for the
requested subject object type on the permission or relation."""
    model_config = ConfigDict(populate_by_name=True)

    looked_up_at: Optional[Dict[str, Any]] = Field(
        None, alias="lookedUpAt"
    )
    subject_object_id: Optional[str] = Field(
        None, alias="subjectObjectId"
    )
    excluded_subject_ids: Optional[List[str]] = Field(
        None, alias="excludedSubjectIds"
    )
    permissionship: Optional[Literal["LOOKUP_PERMISSIONSHIP_UNSPECIFIED", "LOOKUP_PERMISSIONSHIP_HAS_PERMISSION", "LOOKUP_PERMISSIONSHIP_CONDITIONAL_PERMISSION"]] = Field(
        None
    )
    partial_caveat_info: Optional[Dict[str, Any]] = Field(
        None, alias="partialCaveatInfo"
    )
    subject: Optional[Dict[str, Any]] = Field(
        None
    )
    excluded_subjects: Optional[List[Dict[str, Any]]] = Field(
        None, alias="excludedSubjects"
    )
    after_result_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="afterResultCursor"
    )

class V1ObjectReference(BaseModel):
    """ObjectReference is used to refer to a specific object in the system."""
    model_config = ConfigDict(populate_by_name=True)

    object_type: Optional[str] = Field(
        None, alias="objectType"
    )
    object_id: Optional[str] = Field(
        None, alias="objectId"
    )

class V1PartialCaveatInfo(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    missing_required_context: Optional[List[str]] = Field(
        None, alias="missingRequiredContext"
    )

class V1PermissionRelationshipTree(BaseModel):
    """PermissionRelationshipTree is used for representing a tree of a resource and
its permission relationships with other objects."""
    model_config = ConfigDict(populate_by_name=True)

    intermediate: Optional[Dict[str, Any]] = Field(
        None
    )
    leaf: Optional[Dict[str, Any]] = Field(
        None
    )
    expanded_object: Optional[Dict[str, Any]] = Field(
        None, alias="expandedObject"
    )
    expanded_relation: Optional[str] = Field(
        None, alias="expandedRelation"
    )

class V1Precondition(BaseModel):
    """Precondition specifies how and the existence or absence of certain
relationships as expressed through the accompanying filter should affect
whether or not the operation proceeds.

MUST_NOT_MATCH will fail the parent request if any relationships match the
relationships filter.
MUST_MATCH will fail the parent request if there are no
relationships that match the filter."""
    model_config = ConfigDict(populate_by_name=True)

    operation: Optional[Literal["OPERATION_UNSPECIFIED", "OPERATION_MUST_NOT_MATCH", "OPERATION_MUST_MATCH"]] = Field(
        None
    )
    filter: Optional[Dict[str, Any]] = Field(
        None
    )

class V1PreconditionOperation(str, Enum):
    OPERATION_UNSPECIFIED = "OPERATION_UNSPECIFIED"
    OPERATION_MUST_NOT_MATCH = "OPERATION_MUST_NOT_MATCH"
    OPERATION_MUST_MATCH = "OPERATION_MUST_MATCH"

class V1ReadCounterValue(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    relationship_count: Optional[str] = Field(
        None, alias="relationshipCount"
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1ReadRelationshipsRequest(BaseModel):
    """ReadRelationshipsRequest specifies one or more filters used to read matching
relationships within the system."""
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    relationship_filter: Optional[Dict[str, Any]] = Field(
        None, alias="relationshipFilter"
    )
    optional_limit: Optional[int] = Field(
        None, alias="optionalLimit"
    )
    optional_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="optionalCursor"
    )

class V1ReadRelationshipsResponse(BaseModel):
    """ReadRelationshipsResponse contains a Relationship found that matches the
specified relationship filter(s). A instance of this response message will
be streamed to the client for each relationship found."""
    model_config = ConfigDict(populate_by_name=True)

    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )
    relationship: Optional[Dict[str, Any]] = Field(
        None
    )
    after_result_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="afterResultCursor"
    )

class V1ReadSchemaRequest(BaseModel):
    """ReadSchemaRequest returns the schema from the database."""
    model_config = ConfigDict(populate_by_name=True)

    pass

class V1ReadSchemaResponse(BaseModel):
    """ReadSchemaResponse is the resulting data after having read the Object
Definitions from a Schema."""
    model_config = ConfigDict(populate_by_name=True)

    schema_text: Optional[str] = Field(
        None, alias="schemaText"
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1ReflectSchemaRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    consistency: Optional[Dict[str, Any]] = Field(
        None
    )
    optional_filters: Optional[List[Dict[str, Any]]] = Field(
        None, alias="optionalFilters"
    )

class V1ReflectSchemaResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    definitions: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    caveats: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    read_at: Optional[Dict[str, Any]] = Field(
        None, alias="readAt"
    )

class V1ReflectionCaveat(BaseModel):
    """ReflectionCaveat is the representation of a caveat in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    comment: Optional[str] = Field(
        None
    )
    parameters: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    expression: Optional[str] = Field(
        None
    )

class V1ReflectionCaveatParameter(BaseModel):
    """ReflectionCaveatParameter is the representation of a parameter in a caveat."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    type_: Optional[str] = Field(
        None, alias="type"
    )
    parent_caveat_name: Optional[str] = Field(
        None, alias="parentCaveatName"
    )

class V1ReflectionCaveatParameterTypeChange(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    parameter: Optional[Dict[str, Any]] = Field(
        None
    )
    previous_type: Optional[str] = Field(
        None, alias="previousType"
    )

class V1ReflectionDefinition(BaseModel):
    """ReflectionDefinition is the representation of a definition in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    comment: Optional[str] = Field(
        None
    )
    relations: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    permissions: Optional[List[Dict[str, Any]]] = Field(
        None
    )

class V1ReflectionPermission(BaseModel):
    """ReflectionPermission is the representation of a permission in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    comment: Optional[str] = Field(
        None
    )
    parent_definition_name: Optional[str] = Field(
        None, alias="parentDefinitionName"
    )

class V1ReflectionRelation(BaseModel):
    """ReflectionRelation is the representation of a relation in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(
        None
    )
    comment: Optional[str] = Field(
        None
    )
    parent_definition_name: Optional[str] = Field(
        None, alias="parentDefinitionName"
    )
    subject_types: Optional[List[Dict[str, Any]]] = Field(
        None, alias="subjectTypes"
    )

class V1ReflectionRelationReference(BaseModel):
    """ReflectionRelationReference is a reference to a relation or permission in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    definition_name: Optional[str] = Field(
        None, alias="definitionName"
    )
    relation_name: Optional[str] = Field(
        None, alias="relationName"
    )
    is_permission: Optional[bool] = Field(
        None, alias="isPermission"
    )

class V1ReflectionRelationSubjectTypeChange(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    relation: Optional[Dict[str, Any]] = Field(
        None
    )
    changed_subject_type: Optional[Dict[str, Any]] = Field(
        None, alias="changedSubjectType"
    )

class V1ReflectionSchemaDiff(BaseModel):
    """ReflectionSchemaDiff is the representation of a diff between two schemas."""
    model_config = ConfigDict(populate_by_name=True)

    definition_added: Optional[Dict[str, Any]] = Field(
        None, alias="definitionAdded"
    )
    definition_removed: Optional[Dict[str, Any]] = Field(
        None, alias="definitionRemoved"
    )
    definition_doc_comment_changed: Optional[Dict[str, Any]] = Field(
        None, alias="definitionDocCommentChanged"
    )
    relation_added: Optional[Dict[str, Any]] = Field(
        None, alias="relationAdded"
    )
    relation_removed: Optional[Dict[str, Any]] = Field(
        None, alias="relationRemoved"
    )
    relation_doc_comment_changed: Optional[Dict[str, Any]] = Field(
        None, alias="relationDocCommentChanged"
    )
    relation_subject_type_added: Optional[Dict[str, Any]] = Field(
        None, alias="relationSubjectTypeAdded"
    )
    relation_subject_type_removed: Optional[Dict[str, Any]] = Field(
        None, alias="relationSubjectTypeRemoved"
    )
    permission_added: Optional[Dict[str, Any]] = Field(
        None, alias="permissionAdded"
    )
    permission_removed: Optional[Dict[str, Any]] = Field(
        None, alias="permissionRemoved"
    )
    permission_doc_comment_changed: Optional[Dict[str, Any]] = Field(
        None, alias="permissionDocCommentChanged"
    )
    permission_expr_changed: Optional[Dict[str, Any]] = Field(
        None, alias="permissionExprChanged"
    )
    caveat_added: Optional[Dict[str, Any]] = Field(
        None, alias="caveatAdded"
    )
    caveat_removed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatRemoved"
    )
    caveat_doc_comment_changed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatDocCommentChanged"
    )
    caveat_expr_changed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatExprChanged"
    )
    caveat_parameter_added: Optional[Dict[str, Any]] = Field(
        None, alias="caveatParameterAdded"
    )
    caveat_parameter_removed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatParameterRemoved"
    )
    caveat_parameter_type_changed: Optional[Dict[str, Any]] = Field(
        None, alias="caveatParameterTypeChanged"
    )

class V1ReflectionSchemaFilter(BaseModel):
    """ReflectionSchemaFilter is a filter that can be applied to the schema on reflection."""
    model_config = ConfigDict(populate_by_name=True)

    optional_definition_name_filter: Optional[str] = Field(
        None, alias="optionalDefinitionNameFilter"
    )
    optional_caveat_name_filter: Optional[str] = Field(
        None, alias="optionalCaveatNameFilter"
    )
    optional_relation_name_filter: Optional[str] = Field(
        None, alias="optionalRelationNameFilter"
    )
    optional_permission_name_filter: Optional[str] = Field(
        None, alias="optionalPermissionNameFilter"
    )

class V1ReflectionTypeReference(BaseModel):
    """ReflectionTypeReference is the representation of a type reference in the schema."""
    model_config = ConfigDict(populate_by_name=True)

    subject_definition_name: Optional[str] = Field(
        None, alias="subjectDefinitionName"
    )
    optional_caveat_name: Optional[str] = Field(
        None, alias="optionalCaveatName"
    )
    is_terminal_subject: Optional[bool] = Field(
        None, alias="isTerminalSubject"
    )
    optional_relation_name: Optional[str] = Field(
        None, alias="optionalRelationName"
    )
    is_public_wildcard: Optional[bool] = Field(
        None, alias="isPublicWildcard"
    )

class V1Relationship(BaseModel):
    """Relationship specifies how a resource relates to a subject. Relationships
form the data for the graph over which all permissions questions are
answered."""
    model_config = ConfigDict(populate_by_name=True)

    resource: Optional[Dict[str, Any]] = Field(
        None
    )
    relation: Optional[str] = Field(
        None
    )
    subject: Optional[Dict[str, Any]] = Field(
        None
    )
    optional_caveat: Optional[Dict[str, Any]] = Field(
        None, alias="optionalCaveat"
    )
    optional_expires_at: Optional[str] = Field(
        None, alias="optionalExpiresAt"
    )

class V1RelationshipFilter(BaseModel):
    """RelationshipFilter is a collection of filters which when applied to a
relationship will return relationships that have exactly matching fields.

All fields are optional and if left unspecified will not filter relationships,
but at least one field must be specified.

NOTE: The performance of the API will be affected by the selection of fields
on which to filter. If a field is not indexed, the performance of the API
can be significantly slower."""
    model_config = ConfigDict(populate_by_name=True)

    resource_type: Optional[str] = Field(
        None, alias="resourceType"
    )
    optional_resource_id: Optional[str] = Field(
        None, alias="optionalResourceId"
    )
    optional_resource_id_prefix: Optional[str] = Field(
        None, alias="optionalResourceIdPrefix"
    )
    optional_relation: Optional[str] = Field(
        None, alias="optionalRelation"
    )
    optional_subject_filter: Optional[Dict[str, Any]] = Field(
        None, alias="optionalSubjectFilter"
    )

class V1RelationshipUpdate(BaseModel):
    """RelationshipUpdate is used for mutating a single relationship within the
service.

CREATE will create the relationship only if it doesn't exist, and error
otherwise.

TOUCH will upsert the relationship, and will not error if it
already exists.

DELETE will delete the relationship. If the relationship does not exist,
this operation will no-op."""
    model_config = ConfigDict(populate_by_name=True)

    operation: Optional[Literal["OPERATION_UNSPECIFIED", "OPERATION_CREATE", "OPERATION_TOUCH", "OPERATION_DELETE"]] = Field(
        None
    )
    relationship: Optional[Dict[str, Any]] = Field(
        None
    )

class V1RelationshipUpdateOperation(str, Enum):
    OPERATION_UNSPECIFIED = "OPERATION_UNSPECIFIED"
    OPERATION_CREATE = "OPERATION_CREATE"
    OPERATION_TOUCH = "OPERATION_TOUCH"
    OPERATION_DELETE = "OPERATION_DELETE"

class V1ResolvedSubject(BaseModel):
    """ResolvedSubject is a single subject resolved within LookupSubjects."""
    model_config = ConfigDict(populate_by_name=True)

    subject_object_id: Optional[str] = Field(
        None, alias="subjectObjectId"
    )
    permissionship: Optional[Literal["LOOKUP_PERMISSIONSHIP_UNSPECIFIED", "LOOKUP_PERMISSIONSHIP_HAS_PERMISSION", "LOOKUP_PERMISSIONSHIP_CONDITIONAL_PERMISSION"]] = Field(
        None
    )
    partial_caveat_info: Optional[Dict[str, Any]] = Field(
        None, alias="partialCaveatInfo"
    )

class V1SubjectFilter(BaseModel):
    """SubjectFilter specifies a filter on the subject of a relationship.

subject_type is required and all other fields are optional, and will not
impose any additional requirements if left unspecified."""
    model_config = ConfigDict(populate_by_name=True)

    subject_type: Optional[str] = Field(
        None, alias="subjectType"
    )
    optional_subject_id: Optional[str] = Field(
        None, alias="optionalSubjectId"
    )
    optional_relation: Optional[Dict[str, Any]] = Field(
        None, alias="optionalRelation"
    )

class V1SubjectReference(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    object: Optional[Dict[str, Any]] = Field(
        None
    )
    optional_relation: Optional[str] = Field(
        None, alias="optionalRelation"
    )

class V1WatchKind(str, Enum):
    WATCH_KIND_UNSPECIFIED = "WATCH_KIND_UNSPECIFIED"
    WATCH_KIND_INCLUDE_RELATIONSHIP_UPDATES = "WATCH_KIND_INCLUDE_RELATIONSHIP_UPDATES"
    WATCH_KIND_INCLUDE_SCHEMA_UPDATES = "WATCH_KIND_INCLUDE_SCHEMA_UPDATES"
    WATCH_KIND_INCLUDE_CHECKPOINTS = "WATCH_KIND_INCLUDE_CHECKPOINTS"

class V1WatchRequest(BaseModel):
    """WatchRequest specifies what mutations to watch for, and an optional start point for when to start
watching."""
    model_config = ConfigDict(populate_by_name=True)

    optional_object_types: Optional[List[str]] = Field(
        None, alias="optionalObjectTypes"
    )
    optional_start_cursor: Optional[Dict[str, Any]] = Field(
        None, alias="optionalStartCursor"
    )
    optional_relationship_filters: Optional[List[Dict[str, Any]]] = Field(
        None, alias="optionalRelationshipFilters"
    )
    optional_update_kinds: Optional[List[Literal["WATCH_KIND_UNSPECIFIED", "WATCH_KIND_INCLUDE_RELATIONSHIP_UPDATES", "WATCH_KIND_INCLUDE_SCHEMA_UPDATES", "WATCH_KIND_INCLUDE_CHECKPOINTS"]]] = Field(
        None, alias="optionalUpdateKinds"
    )

class V1WatchResponse(BaseModel):
    """WatchResponse contains all mutation events in ascending timestamp order.
This excludes relationships that were deleted because they expired.
The response includes a field that can be used to resume
watching from that point."""
    model_config = ConfigDict(populate_by_name=True)

    updates: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    changes_through: Optional[Dict[str, Any]] = Field(
        None, alias="changesThrough"
    )
    optional_transaction_metadata: Optional[Dict[str, Any]] = Field(
        None, alias="optionalTransactionMetadata"
    )
    schema_updated: Optional[bool] = Field(
        None, alias="schemaUpdated"
    )
    is_checkpoint: Optional[bool] = Field(
        None, alias="isCheckpoint"
    )
    full_revision_metadata: Optional[List[Dict[str, Any]]] = Field(
        None, alias="fullRevisionMetadata"
    )

class V1WriteRelationshipsRequest(BaseModel):
    """WriteRelationshipsRequest contains a list of Relationship mutations that
should be applied to the service. If the optional_preconditions parameter
is included, all of the specified preconditions must also be satisfied before
the write will be committed. All updates will be applied transactionally,
and if any preconditions fail, the entire transaction will be reverted."""
    model_config = ConfigDict(populate_by_name=True)

    updates: Optional[List[Dict[str, Any]]] = Field(
        None
    )
    optional_preconditions: Optional[List[Dict[str, Any]]] = Field(
        None, alias="optionalPreconditions"
    )
    optional_transaction_metadata: Optional[Dict[str, Any]] = Field(
        None, alias="optionalTransactionMetadata"
    )

class V1WriteRelationshipsResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    written_at: Optional[Dict[str, Any]] = Field(
        None, alias="writtenAt"
    )

class V1WriteSchemaRequest(BaseModel):
    """WriteSchemaRequest is the required data used to "upsert" the Schema of a
Permissions System."""
    model_config = ConfigDict(populate_by_name=True)

    schema_: Optional[str] = Field(
        None, alias="schema"
    )

class V1WriteSchemaResponse(BaseModel):
    """WriteSchemaResponse is the resulting data after having written a Schema to
a Permissions System."""
    model_config = ConfigDict(populate_by_name=True)

    written_at: Optional[Dict[str, Any]] = Field(
        None, alias="writtenAt"
    )

class V1ZedToken(BaseModel):
    """ZedToken represents a point in time, or a "revision" in SpiceDB.
It is used to provide causality metadata between Write and read requests (Check, ReadRelationships, LookupResources, LookupSubjects)
and can also be used to start watching for changes from a specific point in time.

See the authzed.api.v1.Consistency message for more information."""
    model_config = ConfigDict(populate_by_name=True)

    token: Optional[str] = Field(
        None
    )
