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

from ..core.unchecked_base_model import UncheckedBaseModel
import typing
from .fulfillment_recipient import FulfillmentRecipient
import pydantic
from .fulfillment_delivery_details_order_fulfillment_delivery_details_schedule_type import (
    FulfillmentDeliveryDetailsOrderFulfillmentDeliveryDetailsScheduleType,
)
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class FulfillmentDeliveryDetails(UncheckedBaseModel):
    """
    Describes delivery details of an order fulfillment.
    """

    recipient: typing.Optional[FulfillmentRecipient] = pydantic.Field(default=None)
    """
    The contact information for the person to receive the fulfillment.
    """

    schedule_type: typing.Optional[FulfillmentDeliveryDetailsOrderFulfillmentDeliveryDetailsScheduleType] = (
        pydantic.Field(default=None)
    )
    """
    Indicates the fulfillment delivery schedule type. If `SCHEDULED`, then
    `deliver_at` is required. If `ASAP`, then `prep_time_duration` is required. The default is `SCHEDULED`.
    See [OrderFulfillmentDeliveryDetailsScheduleType](#type-orderfulfillmentdeliverydetailsscheduletype) for possible values
    """

    placed_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The [timestamp](https://developer.squareup.com/docs/build-basics/working-with-dates)
    indicating when the fulfillment was placed.
    The timestamp must be in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z").
    
    Must be in RFC 3339 timestamp format, e.g., "2016-09-04T23:59:33.123Z".
    """

    deliver_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The [timestamp](https://developer.squareup.com/docs/build-basics/working-with-dates)
    that represents the start of the delivery period.
    When the fulfillment `schedule_type` is `ASAP`, the field is automatically
    set to the current time plus the `prep_time_duration`.
    Otherwise, the application can set this field while the fulfillment `state` is
    `PROPOSED`, `RESERVED`, or `PREPARED` (any time before the
    terminal state such as `COMPLETED`, `CANCELED`, and `FAILED`).
    
    The timestamp must be in RFC 3339 format
    (for example, "2016-09-04T23:59:33.123Z").
    """

    prep_time_duration: typing.Optional[str] = pydantic.Field(default=None)
    """
    The duration of time it takes to prepare and deliver this fulfillment.
    The duration must be in RFC 3339 format (for example, "P1W3D").
    """

    delivery_window_duration: typing.Optional[str] = pydantic.Field(default=None)
    """
    The time period after `deliver_at` in which to deliver the order.
    Applications can set this field when the fulfillment `state` is
    `PROPOSED`, `RESERVED`, or `PREPARED` (any time before the terminal state
    such as `COMPLETED`, `CANCELED`, and `FAILED`).
    
    The duration must be in RFC 3339 format (for example, "P1W3D").
    """

    note: typing.Optional[str] = pydantic.Field(default=None)
    """
    Provides additional instructions about the delivery fulfillment.
    It is displayed in the Square Point of Sale application and set by the API.
    """

    completed_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The [timestamp](https://developer.squareup.com/docs/build-basics/working-with-dates)
    indicates when the seller completed the fulfillment.
    This field is automatically set when  fulfillment `state` changes to `COMPLETED`.
    The timestamp must be in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z").
    """

    in_progress_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The [timestamp](https://developer.squareup.com/docs/build-basics/working-with-dates)
    indicates when the seller started processing the fulfillment.
    This field is automatically set when the fulfillment `state` changes to `RESERVED`.
    The timestamp must be in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z").
    """

    rejected_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The [timestamp](https://developer.squareup.com/docs/build-basics/working-with-dates)
    indicating when the fulfillment was rejected. This field is
    automatically set when the fulfillment `state` changes to `FAILED`.
    The timestamp must be in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z").
    """

    ready_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The [timestamp](https://developer.squareup.com/docs/build-basics/working-with-dates)
    indicating when the seller marked the fulfillment as ready for
    courier pickup. This field is automatically set when the fulfillment `state` changes
    to PREPARED.
    The timestamp must be in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z").
    """

    delivered_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The [timestamp](https://developer.squareup.com/docs/build-basics/working-with-dates)
    indicating when the fulfillment was delivered to the recipient.
    The timestamp must be in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z").
    """

    canceled_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The [timestamp](https://developer.squareup.com/docs/build-basics/working-with-dates)
    indicating when the fulfillment was canceled. This field is automatically
    set when the fulfillment `state` changes to `CANCELED`.
    
    The timestamp must be in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z").
    """

    cancel_reason: typing.Optional[str] = pydantic.Field(default=None)
    """
    The delivery cancellation reason. Max length: 100 characters.
    """

    courier_pickup_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The [timestamp](https://developer.squareup.com/docs/build-basics/working-with-dates)
    indicating when an order can be picked up by the courier for delivery.
    The timestamp must be in RFC 3339 format (for example, "2016-09-04T23:59:33.123Z").
    """

    courier_pickup_window_duration: typing.Optional[str] = pydantic.Field(default=None)
    """
    The time period after `courier_pickup_at` in which the courier should pick up the order.
    The duration must be in RFC 3339 format (for example, "P1W3D").
    """

    is_no_contact_delivery: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Whether the delivery is preferred to be no contact.
    """

    dropoff_notes: typing.Optional[str] = pydantic.Field(default=None)
    """
    A note to provide additional instructions about how to deliver the order.
    """

    courier_provider_name: typing.Optional[str] = pydantic.Field(default=None)
    """
    The name of the courier provider.
    """

    courier_support_phone_number: typing.Optional[str] = pydantic.Field(default=None)
    """
    The support phone number of the courier.
    """

    square_delivery_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The identifier for the delivery created by Square.
    """

    external_delivery_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The identifier for the delivery created by the third-party courier service.
    """

    managed_delivery: typing.Optional[bool] = pydantic.Field(default=None)
    """
    The flag to indicate the delivery is managed by a third party (ie DoorDash), which means
    we may not receive all recipient information for PII purposes.
    """

    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
