# generated by datamodel-codegen:
#   filename:  order_schema.json
#   timestamp: 2025-08-03T16:40:11+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Optional

from pydantic import BaseModel, Field


class IssuerRef(BaseModel):
    group: Optional[str] = Field(
        None, description='Group of the resource being referred to.'
    )
    kind: Optional[str] = Field(
        None, description='Kind of the resource being referred to.'
    )
    name: str = Field(..., description='Name of the resource being referred to.')


class Spec(BaseModel):
    commonName: Optional[str] = Field(
        None,
        description='CommonName is the common name as specified on the DER encoded CSR.\nIf specified, this value must also be present in `dnsNames` or `ipAddresses`.\nThis field must match the corresponding field on the DER encoded CSR.',
    )
    dnsNames: Optional[list[str]] = Field(
        None,
        description='DNSNames is a list of DNS names that should be included as part of the Order\nvalidation process.\nThis field must match the corresponding field on the DER encoded CSR.',
    )
    duration: Optional[str] = Field(
        None,
        description='Duration is the duration for the not after date for the requested certificate.\nthis is set on order creation as pe the ACME spec.',
    )
    ipAddresses: Optional[list[str]] = Field(
        None,
        description='IPAddresses is a list of IP addresses that should be included as part of the Order\nvalidation process.\nThis field must match the corresponding field on the DER encoded CSR.',
    )
    issuerRef: IssuerRef = Field(
        ...,
        description="IssuerRef references a properly configured ACME-type Issuer which should\nbe used to create this Order.\nIf the Issuer does not exist, processing will be retried.\nIf the Issuer is not an 'ACME' Issuer, an error will be returned and the\nOrder will be marked as failed.",
    )
    profile: Optional[str] = Field(
        None,
        description="Profile allows requesting a certificate profile from the ACME server.\nSupported profiles are listed by the server's ACME directory URL.",
    )
    request: str = Field(
        ...,
        description='Certificate signing request bytes in DER encoding.\nThis will be used when finalizing the order.\nThis field must be set on the order.',
    )


class Challenge(BaseModel):
    token: str = Field(
        ...,
        description="Token is the token that must be presented for this challenge.\nThis is used to compute the 'key' that must also be presented.",
    )
    type: str = Field(
        ...,
        description="Type is the type of challenge being offered, e.g., 'http-01', 'dns-01',\n'tls-sni-01', etc.\nThis is the raw value retrieved from the ACME server.\nOnly 'http-01' and 'dns-01' are supported by cert-manager, other values\nwill be ignored.",
    )
    url: str = Field(
        ...,
        description='URL is the URL of this challenge. It can be used to retrieve additional\nmetadata about the Challenge from the ACME server.',
    )


class InitialState(Enum):
    valid = 'valid'
    ready = 'ready'
    pending = 'pending'
    processing = 'processing'
    invalid = 'invalid'
    expired = 'expired'
    errored = 'errored'


class Authorization(BaseModel):
    challenges: Optional[list[Challenge]] = Field(
        None,
        description='Challenges specifies the challenge types offered by the ACME server.\nOne of these challenge types will be selected when validating the DNS\nname and an appropriate Challenge resource will be created to perform\nthe ACME challenge process.',
    )
    identifier: Optional[str] = Field(
        None,
        description='Identifier is the DNS name to be validated as part of this authorization',
    )
    initialState: Optional[InitialState] = Field(
        None,
        description="InitialState is the initial state of the ACME authorization when first\nfetched from the ACME server.\nIf an Authorization is already 'valid', the Order controller will not\ncreate a Challenge resource for the authorization. This will occur when\nworking with an ACME server that enables 'authz reuse' (such as Let's\nEncrypt's production endpoint).\nIf not set and 'identifier' is set, the state is assumed to be pending\nand a Challenge will be created.",
    )
    url: str = Field(
        ..., description='URL is the URL of the Authorization that must be completed'
    )
    wildcard: Optional[bool] = Field(
        None,
        description="Wildcard will be true if this authorization is for a wildcard DNS name.\nIf this is true, the identifier will be the *non-wildcard* version of\nthe DNS name.\nFor example, if '*.example.com' is the DNS name being validated, this\nfield will be 'true' and the 'identifier' field will be 'example.com'.",
    )


class State(Enum):
    valid = 'valid'
    ready = 'ready'
    pending = 'pending'
    processing = 'processing'
    invalid = 'invalid'
    expired = 'expired'
    errored = 'errored'


class Status(BaseModel):
    authorizations: Optional[list[Authorization]] = Field(
        None,
        description='Authorizations contains data returned from the ACME server on what\nauthorizations must be completed in order to validate the DNS names\nspecified on the Order.',
    )
    certificate: Optional[str] = Field(
        None,
        description="Certificate is a copy of the PEM encoded certificate for this Order.\nThis field will be populated after the order has been successfully\nfinalized with the ACME server, and the order has transitioned to the\n'valid' state.",
    )
    failureTime: Optional[datetime] = Field(
        None,
        description='FailureTime stores the time that this order failed.\nThis is used to influence garbage collection and back-off.',
    )
    finalizeURL: Optional[str] = Field(
        None,
        description='FinalizeURL of the Order.\nThis is used to obtain certificates for this order once it has been completed.',
    )
    reason: Optional[str] = Field(
        None,
        description='Reason optionally provides more information about a why the order is in\nthe current state.',
    )
    state: Optional[State] = Field(
        None,
        description="State contains the current state of this Order resource.\nStates 'success' and 'expired' are 'final'",
    )
    url: Optional[str] = Field(
        None,
        description='URL of the Order.\nThis will initially be empty when the resource is first created.\nThe Order controller will populate this field when the Order is first processed.\nThis field will be immutable after it is initially set.',
    )


class Order(BaseModel):
    apiVersion: Optional[str] = Field(
        None,
        description='APIVersion defines the versioned schema of this representation of an object.\nServers should convert recognized schemas to the latest internal value, and\nmay reject unrecognized values.\nMore info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources',
    )
    kind: Optional[str] = Field(
        None,
        description='Kind is a string value representing the REST resource this object represents.\nServers may infer this from the endpoint the client submits requests to.\nCannot be updated.\nIn CamelCase.\nMore info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds',
    )
    metadata: dict[str, Any]
    spec: Spec
    status: Optional[Status] = None
