# This file was auto-generated by Fern from our API Definition.

from ..core.unchecked_base_model import UncheckedBaseModel
import typing
import pydantic
import typing_extensions
from ..core.serialization import FieldMetadata
from .custom_attribute_definition_visibility import CustomAttributeDefinitionVisibility
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class CustomAttributeDefinition(UncheckedBaseModel):
    """
    Represents a definition for custom attribute values. A custom attribute definition
    specifies the key, visibility, schema, and other properties for a custom attribute.
    """

    key: typing.Optional[str] = pydantic.Field(default=None)
    """
    The identifier
    of the custom attribute definition and its corresponding custom attributes. This value
    can be a simple key, which is the key that is provided when the custom attribute definition
    is created, or a qualified key, if the requesting
    application is not the definition owner. The qualified key consists of the application ID
    of the custom attribute definition owner
    followed by the simple key that was provided when the definition was created. It has the
    format application_id:simple key.
    
    The value for a simple key can contain up to 60 alphanumeric characters, periods (.),
    underscores (_), and hyphens (-).
    
    This field can not be changed
    after the custom attribute definition is created. This field is required when creating
    a definition and must be unique per application, seller, and resource type.
    """

    schema_: typing_extensions.Annotated[
        typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]], FieldMetadata(alias="schema")
    ] = pydantic.Field(default=None)
    """
    The JSON schema for the custom attribute definition, which determines the data type of the corresponding custom attributes. For more information,
    see [Custom Attributes Overview](https://developer.squareup.com/docs/devtools/customattributes/overview). This field is required when creating a definition.
    """

    name: typing.Optional[str] = pydantic.Field(default=None)
    """
    The name of the custom attribute definition for API and seller-facing UI purposes. The name must
    be unique within the seller and application pair. This field is required if the
    `visibility` field is `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
    """

    description: typing.Optional[str] = pydantic.Field(default=None)
    """
    Seller-oriented description of the custom attribute definition, including any constraints
    that the seller should observe. May be displayed as a tooltip in Square UIs. This field is
    required if the `visibility` field is `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
    """

    visibility: typing.Optional[CustomAttributeDefinitionVisibility] = pydantic.Field(default=None)
    """
    Specifies how the custom attribute definition and its values should be shared with
    the seller and other applications. If no value is specified, the value defaults to `VISIBILITY_HIDDEN`.
    See [Visibility](#type-visibility) for possible values
    """

    version: typing.Optional[int] = pydantic.Field(default=None)
    """
    Read only. The current version of the custom attribute definition.
    The value is incremented each time the custom attribute definition is updated.
    When updating a custom attribute definition, you can provide this field
    and specify the current version of the custom attribute definition to enable
    [optimistic concurrency](https://developer.squareup.com/docs/build-basics/common-api-patterns/optimistic-concurrency).
    
    On writes, this field must be set to the latest version. Stale writes are rejected.
    
    This field can also be used to enforce strong consistency for reads. For more information about strong consistency for reads,
    see [Custom Attributes Overview](https://developer.squareup.com/docs/devtools/customattributes/overview).
    """

    updated_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The timestamp that indicates when the custom attribute definition was created or most recently updated,
    in RFC 3339 format.
    """

    created_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The timestamp that indicates when the custom attribute definition was created, in RFC 3339 format.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
