# generated by datamodel-codegen:
#   filename:  certificaterequest_schema.json
#   timestamp: 2025-08-03T16:40:07+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 Usage(Enum):
    signing = 'signing'
    digital_signature = 'digital signature'
    content_commitment = 'content commitment'
    key_encipherment = 'key encipherment'
    key_agreement = 'key agreement'
    data_encipherment = 'data encipherment'
    cert_sign = 'cert sign'
    crl_sign = 'crl sign'
    encipher_only = 'encipher only'
    decipher_only = 'decipher only'
    any = 'any'
    server_auth = 'server auth'
    client_auth = 'client auth'
    code_signing = 'code signing'
    email_protection = 'email protection'
    s_mime = 's/mime'
    ipsec_end_system = 'ipsec end system'
    ipsec_tunnel = 'ipsec tunnel'
    ipsec_user = 'ipsec user'
    timestamping = 'timestamping'
    ocsp_signing = 'ocsp signing'
    microsoft_sgc = 'microsoft sgc'
    netscape_sgc = 'netscape sgc'


class Spec(BaseModel):
    duration: Optional[str] = Field(
        None,
        description="Requested 'duration' (i.e. lifetime) of the Certificate. Note that the\nissuer may choose to ignore the requested duration, just like any other\nrequested attribute.",
    )
    extra: Optional[dict[str, list[str]]] = Field(
        None,
        description='Extra contains extra attributes of the user that created the CertificateRequest.\nPopulated by the cert-manager webhook on creation and immutable.',
    )
    groups: Optional[list[str]] = Field(
        None,
        description='Groups contains group membership of the user that created the CertificateRequest.\nPopulated by the cert-manager webhook on creation and immutable.',
    )
    isCA: Optional[bool] = Field(
        None,
        description='Requested basic constraints isCA value. Note that the issuer may choose\nto ignore the requested isCA value, just like any other requested attribute.\n\nNOTE: If the CSR in the `Request` field has a BasicConstraints extension,\nit must have the same isCA value as specified here.\n\nIf true, this will automatically add the `cert sign` usage to the list\nof requested `usages`.',
    )
    issuerRef: IssuerRef = Field(
        ...,
        description='Reference to the issuer responsible for issuing the certificate.\nIf the issuer is namespace-scoped, it must be in the same namespace\nas the Certificate. If the issuer is cluster-scoped, it can be used\nfrom any namespace.\n\nThe `name` field of the reference must always be specified.',
    )
    request: str = Field(
        ...,
        description='The PEM-encoded X.509 certificate signing request to be submitted to the\nissuer for signing.\n\nIf the CSR has a BasicConstraints extension, its isCA attribute must\nmatch the `isCA` value of this CertificateRequest.\nIf the CSR has a KeyUsage extension, its key usages must match the\nkey usages in the `usages` field of this CertificateRequest.\nIf the CSR has a ExtKeyUsage extension, its extended key usages\nmust match the extended key usages in the `usages` field of this\nCertificateRequest.',
    )
    uid: Optional[str] = Field(
        None,
        description='UID contains the uid of the user that created the CertificateRequest.\nPopulated by the cert-manager webhook on creation and immutable.',
    )
    usages: Optional[list[Usage]] = Field(
        None,
        description='Requested key usages and extended key usages.\n\nNOTE: If the CSR in the `Request` field has uses the KeyUsage or\nExtKeyUsage extension, these extensions must have the same values\nas specified here without any additional values.\n\nIf unset, defaults to `digital signature` and `key encipherment`.',
    )
    username: Optional[str] = Field(
        None,
        description='Username contains the name of the user that created the CertificateRequest.\nPopulated by the cert-manager webhook on creation and immutable.',
    )


class Status1(Enum):
    True_ = 'True'
    False_ = 'False'
    Unknown = 'Unknown'


class Condition(BaseModel):
    lastTransitionTime: Optional[datetime] = Field(
        None,
        description='LastTransitionTime is the timestamp corresponding to the last status\nchange of this condition.',
    )
    message: Optional[str] = Field(
        None,
        description='Message is a human readable description of the details of the last\ntransition, complementing reason.',
    )
    reason: Optional[str] = Field(
        None,
        description="Reason is a brief machine readable explanation for the condition's last\ntransition.",
    )
    status: Status1 = Field(
        ..., description='Status of the condition, one of (`True`, `False`, `Unknown`).'
    )
    type: str = Field(
        ...,
        description='Type of the condition, known values are (`Ready`, `InvalidRequest`,\n`Approved`, `Denied`).',
    )


class Status(BaseModel):
    ca: Optional[str] = Field(
        None,
        description='The PEM encoded X.509 certificate of the signer, also known as the CA\n(Certificate Authority).\nThis is set on a best-effort basis by different issuers.\nIf not set, the CA is assumed to be unknown/not available.',
    )
    certificate: Optional[str] = Field(
        None,
        description='The PEM encoded X.509 certificate resulting from the certificate\nsigning request.\nIf not set, the CertificateRequest has either not been completed or has\nfailed. More information on failure can be found by checking the\n`conditions` field.',
    )
    conditions: Optional[list[Condition]] = Field(
        None,
        description='List of status conditions to indicate the status of a CertificateRequest.\nKnown condition types are `Ready`, `InvalidRequest`, `Approved` and `Denied`.',
    )
    failureTime: Optional[datetime] = Field(
        None,
        description='FailureTime stores the time that this CertificateRequest failed. This is\nused to influence garbage collection and back-off.',
    )


class Certificaterequest(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: Optional[dict[str, Any]] = None
    spec: Optional[Spec] = Field(
        None,
        description='Specification of the desired state of the CertificateRequest resource.\nhttps://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status',
    )
    status: Optional[Status] = Field(
        None,
        description='Status of the CertificateRequest.\nThis is set and managed automatically.\nRead-only.\nMore info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status',
    )
