# Copyright 2026 UCP Authors
#
# 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
#
#     http://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.

# generated by datamodel-codegen
# pylint: disable=all
# pyformat: disable

from __future__ import annotations

from typing import Literal

from pydantic import AnyUrl, AwareDatetime, BaseModel, ConfigDict

from .. import ucp as ucp_1
from . import payment as payment_1
from .types import buyer as buyer_1
from .types import context as context_1
from .types import line_item, link, message, order_confirmation, total


class Checkout(BaseModel):
    """
    Base checkout schema. Extensions compose onto this using allOf.
    """

    model_config = ConfigDict(
        extra="allow",
    )
    ucp: ucp_1.UcpMetadata
    id: str
    """
    Unique identifier of the checkout session.
    """
    line_items: list[line_item.LineItem]
    """
    List of line items being checked out.
    """
    buyer: buyer_1.Buyer | None = None
    """
    Representation of the buyer.
    """
    context: context_1.Context | None = None
    status: Literal[
        "incomplete",
        "requires_escalation",
        "ready_for_complete",
        "complete_in_progress",
        "completed",
        "canceled",
    ]
    """
    Checkout state indicating the current phase and required action. See Checkout Status lifecycle documentation for state transition details.
    """
    currency: str
    """
    ISO 4217 currency code reflecting the merchant's market determination. Derived from address, context, and geo IP—buyers provide signals, merchants determine currency.
    """
    totals: list[total.Total]
    """
    Different cart totals.
    """
    messages: list[message.Message] | None = None
    """
    List of messages with error and info about the checkout session state.
    """
    links: list[link.Link]
    """
    Links to be displayed by the platform (Privacy Policy, TOS). Mandatory for legal compliance.
    """
    expires_at: AwareDatetime | None = None
    """
    RFC 3339 expiry timestamp. Default TTL is 6 hours from creation if not sent.
    """
    continue_url: AnyUrl | None = None
    """
    URL for checkout handoff and session recovery. MUST be provided when status is requires_escalation. See specification for format and availability requirements.
    """
    payment: payment_1.Payment | None = None
    order: order_confirmation.OrderConfirmation | None = None
    """
    Details about an order created for this checkout session.
    """
