# generated by datamodel-codegen:
#   filename:  account/sync_accounts_response.json
#   timestamp: 2026-02-27T02:10:10+00:00

from __future__ import annotations

from enum import Enum
from typing import Any, Annotated

from adcp.types.base import AdCPBaseModel
from pydantic import AnyUrl, AwareDatetime, ConfigDict, Field

from ..core import brand_ref
from ..core import context as context_1
from ..core import error
from ..core import ext as ext_1


class AccountScope(Enum):
    operator = 'operator'
    brand = 'brand'
    operator_brand = 'operator_brand'
    agent = 'agent'


class Action(Enum):
    created = 'created'
    updated = 'updated'
    unchanged = 'unchanged'
    failed = 'failed'


class Billing(Enum):
    operator = 'operator'
    agent = 'agent'


class CreditLimit(AdCPBaseModel):
    amount: Annotated[float, Field(ge=0.0)]
    currency: Annotated[str, Field(pattern='^[A-Z]{3}$')]


class Setup(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    expires_at: Annotated[
        AwareDatetime | None, Field(description='When this setup link expires')
    ] = None
    message: Annotated[str, Field(description="Human-readable description of what's needed")]
    url: Annotated[
        AnyUrl | None,
        Field(
            description='URL where the human can complete the required action (credit application, legal agreement, add funds)'
        ),
    ] = None


class Status(Enum):
    active = 'active'
    pending_approval = 'pending_approval'
    rejected = 'rejected'
    payment_required = 'payment_required'
    suspended = 'suspended'
    closed = 'closed'


class Account(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    account_scope: Annotated[
        AccountScope | None,
        Field(
            description="How the seller scoped this account. operator: shared across all brands for this operator. brand: shared across all operators for this brand. operator_brand: dedicated to this operator+brand pair. agent: the agent's default account."
        ),
    ] = None
    action: Annotated[
        Action,
        Field(
            description='Action taken for this account. created: new account provisioned. updated: existing account modified. unchanged: no changes needed. failed: could not process (see errors).'
        ),
    ]
    billing: Annotated[
        Billing | None,
        Field(description='Who is invoiced on this account. Matches the requested billing model.'),
    ] = None
    brand: Annotated[
        brand_ref.BrandReference, Field(description='Brand reference, echoed from the request')
    ]
    credit_limit: CreditLimit | None = None
    errors: Annotated[
        list[error.Error] | None,
        Field(description="Per-account errors (only present when action is 'failed')"),
    ] = None
    name: Annotated[
        str | None, Field(description='Human-readable account name assigned by the seller')
    ] = None
    operator: Annotated[str, Field(description='Operator domain, echoed from request')]
    payment_terms: Annotated[
        str | None, Field(description="Payment terms (e.g., 'net_30', 'prepay')")
    ] = None
    rate_card: Annotated[str | None, Field(description='Rate card applied to this account')] = None
    sandbox: Annotated[
        bool | None,
        Field(description='Whether this is a sandbox account, echoed from the request.'),
    ] = None
    setup: Annotated[
        Setup | None,
        Field(
            description='Setup information for pending accounts. Provides the agent (or human) with next steps to complete account activation.'
        ),
    ] = None
    status: Annotated[
        Status,
        Field(
            description='Account status. active: ready for use. pending_approval: seller reviewing (credit, legal). rejected: seller declined the account request. payment_required: credit limit reached or funds depleted. suspended: was active, now paused. closed: was active, now terminated.'
        ),
    ]
    warnings: Annotated[
        list[str] | None, Field(description='Non-fatal warnings about this account')
    ] = None


class SyncAccountsResponse1(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    accounts: Annotated[list[Account], Field(description='Results for each account processed')]
    context: context_1.ContextObject | None = None
    dry_run: Annotated[
        bool | None, Field(description='Whether this was a dry run (no actual changes made)')
    ] = None
    ext: ext_1.ExtensionObject | None = None


class SyncAccountsResponse2(AdCPBaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    context: context_1.ContextObject | None = None
    errors: Annotated[
        list[error.Error],
        Field(
            description='Operation-level errors (e.g., authentication failure, service unavailable)',
            min_length=1,
        ),
    ]
    ext: ext_1.ExtensionObject | None = None


SyncAccountsResponse = SyncAccountsResponse1 | SyncAccountsResponse2
