use crate::prelude::*;

// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -f /home/mmoreiradj/git/crd-rs/crds/cilium/v2/ciliumbgpnodeconfigs.yaml --schema=derived -d --hide-prelude
// kopium version: 0.22.5

/// Spec is the specification of the desired behavior of the CiliumBGPNodeConfig.
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[kube(
    group = "cilium.io",
    version = "v2",
    kind = "CiliumBGPNodeConfig",
    plural = "ciliumbgpnodeconfigs"
)]
#[kube(status = "CiliumBgpNodeConfigStatus")]
pub struct CiliumBgpNodeConfigSpec {
    /// BGPInstances is a list of BGP router instances on the node.
    #[serde(rename = "bgpInstances")]
    pub bgp_instances: Vec<CiliumBgpNodeConfigBgpInstances>,
}

/// CiliumBGPNodeInstance is a single BGP router instance configuration on the node.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigBgpInstances {
    /// LocalASN is the ASN of this virtual router.
    /// Supports extended 32bit ASNs.
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "localASN")]
    pub local_asn: Option<i64>,
    /// LocalPort is the port on which the BGP daemon listens for incoming connections.
    ///
    /// If not specified, BGP instance will not listen for incoming connections.
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "localPort")]
    pub local_port: Option<i32>,
    /// Name is the name of the BGP instance. This name is used to identify the BGP instance on the node.
    pub name: String,
    /// Peers is a list of neighboring BGP peers for this virtual router
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub peers: Option<Vec<CiliumBgpNodeConfigBgpInstancesPeers>>,
    /// RouterID is the BGP router ID of this virtual router.
    /// This configuration is derived from CiliumBGPNodeConfigOverride resource.
    ///
    /// If not specified, the router ID will be derived from the node local address.
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "routerID")]
    pub router_id: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigBgpInstancesPeers {
    /// AutoDiscovery is the configuration for auto-discovery of the peer address.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "autoDiscovery"
    )]
    pub auto_discovery: Option<CiliumBgpNodeConfigBgpInstancesPeersAutoDiscovery>,
    /// LocalAddress is the IP address of the local interface to use for the peering session.
    /// This configuration is derived from CiliumBGPNodeConfigOverride resource. If not specified, the local address will be used for setting up peering.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "localAddress"
    )]
    pub local_address: Option<String>,
    /// Name is the name of the BGP peer. This name is used to identify the BGP peer for the BGP instance.
    pub name: String,
    /// PeerASN is the ASN of the peer BGP router.
    /// Supports extended 32bit ASNs
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "peerASN")]
    pub peer_asn: Option<i64>,
    /// PeerAddress is the IP address of the neighbor.
    /// Supports IPv4 and IPv6 addresses.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "peerAddress"
    )]
    pub peer_address: Option<String>,
    /// PeerConfigRef is a reference to a peer configuration resource.
    /// If not specified, the default BGP configuration is used for this peer.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "peerConfigRef"
    )]
    pub peer_config_ref: Option<CiliumBgpNodeConfigBgpInstancesPeersPeerConfigRef>,
}

/// AutoDiscovery is the configuration for auto-discovery of the peer address.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigBgpInstancesPeersAutoDiscovery {
    /// defaultGateway is the configuration for auto-discovery of the default gateway.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "defaultGateway"
    )]
    pub default_gateway: Option<CiliumBgpNodeConfigBgpInstancesPeersAutoDiscoveryDefaultGateway>,
    /// mode is the mode of the auto-discovery.
    pub mode: CiliumBgpNodeConfigBgpInstancesPeersAutoDiscoveryMode,
}

/// defaultGateway is the configuration for auto-discovery of the default gateway.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigBgpInstancesPeersAutoDiscoveryDefaultGateway {
    /// addressFamily is the address family of the default gateway.
    #[serde(rename = "addressFamily")]
    pub address_family:
        CiliumBgpNodeConfigBgpInstancesPeersAutoDiscoveryDefaultGatewayAddressFamily,
}

/// defaultGateway is the configuration for auto-discovery of the default gateway.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub enum CiliumBgpNodeConfigBgpInstancesPeersAutoDiscoveryDefaultGatewayAddressFamily {
    #[serde(rename = "ipv4")]
    Ipv4,
    #[serde(rename = "ipv6")]
    Ipv6,
}

/// AutoDiscovery is the configuration for auto-discovery of the peer address.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub enum CiliumBgpNodeConfigBgpInstancesPeersAutoDiscoveryMode {
    DefaultGateway,
}

/// PeerConfigRef is a reference to a peer configuration resource.
/// If not specified, the default BGP configuration is used for this peer.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigBgpInstancesPeersPeerConfigRef {
    /// Name is the name of the peer config resource.
    /// Name refers to the name of a Kubernetes object (typically a CiliumBGPPeerConfig).
    pub name: String,
}

/// Status is the most recently observed status of the CiliumBGPNodeConfig.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigStatus {
    /// BGPInstances is the status of the BGP instances on the node.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "bgpInstances"
    )]
    pub bgp_instances: Option<Vec<CiliumBgpNodeConfigStatusBgpInstances>>,
    /// The current conditions of the CiliumBGPNodeConfig
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub conditions: Option<Vec<Condition>>,
}

#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigStatusBgpInstances {
    /// LocalASN is the ASN of this BGP instance.
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "localASN")]
    pub local_asn: Option<i64>,
    /// Name is the name of the BGP instance. This name is used to identify the BGP instance on the node.
    pub name: String,
    /// PeerStatuses is the state of the BGP peers for this BGP instance.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub peers: Option<Vec<CiliumBgpNodeConfigStatusBgpInstancesPeers>>,
}

/// CiliumBGPNodePeerStatus is the status of a BGP peer.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigStatusBgpInstancesPeers {
    /// EstablishedTime is the time when the peering session was established.
    /// It is represented in RFC3339 form and is in UTC.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "establishedTime"
    )]
    pub established_time: Option<String>,
    /// Name is the name of the BGP peer.
    pub name: String,
    /// PeerASN is the ASN of the neighbor.
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "peerASN")]
    pub peer_asn: Option<i64>,
    /// PeerAddress is the IP address of the neighbor.
    #[serde(rename = "peerAddress")]
    pub peer_address: String,
    /// PeeringState is last known state of the peering session.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "peeringState"
    )]
    pub peering_state: Option<String>,
    /// RouteCount is the number of routes exchanged with this peer per AFI/SAFI.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "routeCount"
    )]
    pub route_count: Option<Vec<CiliumBgpNodeConfigStatusBgpInstancesPeersRouteCount>>,
    /// Timers is the state of the negotiated BGP timers for this peer.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub timers: Option<CiliumBgpNodeConfigStatusBgpInstancesPeersTimers>,
}

#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigStatusBgpInstancesPeersRouteCount {
    /// Advertised is the number of routes advertised to this peer.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub advertised: Option<i32>,
    /// Afi is the Address Family Identifier (AFI) of the family.
    pub afi: CiliumBgpNodeConfigStatusBgpInstancesPeersRouteCountAfi,
    /// Received is the number of routes received from this peer.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub received: Option<i32>,
    /// Safi is the Subsequent Address Family Identifier (SAFI) of the family.
    pub safi: CiliumBgpNodeConfigStatusBgpInstancesPeersRouteCountSafi,
}

#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub enum CiliumBgpNodeConfigStatusBgpInstancesPeersRouteCountAfi {
    #[serde(rename = "ipv4")]
    Ipv4,
    #[serde(rename = "ipv6")]
    Ipv6,
    #[serde(rename = "l2vpn")]
    L2vpn,
    #[serde(rename = "ls")]
    Ls,
    #[serde(rename = "opaque")]
    Opaque,
}

#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub enum CiliumBgpNodeConfigStatusBgpInstancesPeersRouteCountSafi {
    #[serde(rename = "unicast")]
    Unicast,
    #[serde(rename = "multicast")]
    Multicast,
    #[serde(rename = "mpls_label")]
    MplsLabel,
    #[serde(rename = "encapsulation")]
    Encapsulation,
    #[serde(rename = "vpls")]
    Vpls,
    #[serde(rename = "evpn")]
    Evpn,
    #[serde(rename = "ls")]
    Ls,
    #[serde(rename = "sr_policy")]
    SrPolicy,
    #[serde(rename = "mup")]
    Mup,
    #[serde(rename = "mpls_vpn")]
    MplsVpn,
    #[serde(rename = "mpls_vpn_multicast")]
    MplsVpnMulticast,
    #[serde(rename = "route_target_constraints")]
    RouteTargetConstraints,
    #[serde(rename = "flowspec_unicast")]
    FlowspecUnicast,
    #[serde(rename = "flowspec_vpn")]
    FlowspecVpn,
    #[serde(rename = "key_value")]
    KeyValue,
}

/// Timers is the state of the negotiated BGP timers for this peer.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpNodeConfigStatusBgpInstancesPeersTimers {
    /// AppliedHoldTimeSeconds is the negotiated hold time for this peer.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "appliedHoldTimeSeconds"
    )]
    pub applied_hold_time_seconds: Option<i32>,
    /// AppliedKeepaliveSeconds is the negotiated keepalive time for this peer.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "appliedKeepaliveSeconds"
    )]
    pub applied_keepalive_seconds: Option<i32>,
}
