use crate::prelude::*;

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

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[kube(
    group = "cilium.io",
    version = "v2",
    kind = "CiliumBGPAdvertisement",
    plural = "ciliumbgpadvertisements"
)]
pub struct CiliumBgpAdvertisementSpec {
    /// Advertisements is a list of BGP advertisements.
    pub advertisements: Vec<CiliumBgpAdvertisementAdvertisements>,
}

/// BGPAdvertisement defines which routes Cilium should advertise to BGP peers. Optionally, additional attributes can be
/// set to the advertised routes.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpAdvertisementAdvertisements {
    /// AdvertisementType defines type of advertisement which has to be advertised.
    #[serde(rename = "advertisementType")]
    pub advertisement_type: CiliumBgpAdvertisementAdvertisementsAdvertisementType,
    /// Attributes defines additional attributes to set to the advertised routes.
    /// If not specified, no additional attributes are set.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub attributes: Option<CiliumBgpAdvertisementAdvertisementsAttributes>,
    /// Interface defines configuration options for the "Interface" advertisementType.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub interface: Option<CiliumBgpAdvertisementAdvertisementsInterface>,
    /// Selector is a label selector to select objects of the type specified by AdvertisementType.
    /// For the PodCIDR AdvertisementType it is not applicable. For other advertisement types,
    /// if not specified, no objects of the type specified by AdvertisementType are selected for advertisement.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub selector: Option<CiliumBgpAdvertisementAdvertisementsSelector>,
    /// Service defines configuration options for the "Service" advertisementType.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service: Option<CiliumBgpAdvertisementAdvertisementsService>,
}

/// BGPAdvertisement defines which routes Cilium should advertise to BGP peers. Optionally, additional attributes can be
/// set to the advertised routes.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub enum CiliumBgpAdvertisementAdvertisementsAdvertisementType {
    #[serde(rename = "PodCIDR")]
    PodCidr,
    #[serde(rename = "CiliumPodIPPool")]
    CiliumPodIpPool,
    Service,
    Interface,
}

/// Attributes defines additional attributes to set to the advertised routes.
/// If not specified, no additional attributes are set.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpAdvertisementAdvertisementsAttributes {
    /// Communities sets the community attributes in the route.
    /// If not specified, no community attribute is set.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub communities: Option<CiliumBgpAdvertisementAdvertisementsAttributesCommunities>,
    /// LocalPreference sets the local preference attribute in the route.
    /// If not specified, no local preference attribute is set.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "localPreference"
    )]
    pub local_preference: Option<i64>,
}

/// Communities sets the community attributes in the route.
/// If not specified, no community attribute is set.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpAdvertisementAdvertisementsAttributesCommunities {
    /// Large holds a list of the BGP Large Communities Attribute (RFC 8092) values.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub large: Option<Vec<String>>,
    /// Standard holds a list of "standard" 32-bit BGP Communities Attribute (RFC 1997) values defined as numeric values.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub standard: Option<Vec<String>>,
    /// WellKnown holds a list "standard" 32-bit BGP Communities Attribute (RFC 1997) values defined as
    /// well-known string aliases to their numeric values.
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "wellKnown")]
    pub well_known: Option<Vec<String>>,
}

/// Interface defines configuration options for the "Interface" advertisementType.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpAdvertisementAdvertisementsInterface {
    /// Name of local interface of whose IP addresses will be advertised via BGP.
    /// Each IP address applied on the interface is advertised as a /32 prefix (for IPv4) or a /128 prefix (for IPv6).
    pub name: String,
}

/// Selector is a label selector to select objects of the type specified by AdvertisementType.
/// For the PodCIDR AdvertisementType it is not applicable. For other advertisement types,
/// if not specified, no objects of the type specified by AdvertisementType are selected for advertisement.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpAdvertisementAdvertisementsSelector {
    /// matchExpressions is a list of label selector requirements. The requirements are ANDed.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "matchExpressions"
    )]
    pub match_expressions:
        Option<Vec<CiliumBgpAdvertisementAdvertisementsSelectorMatchExpressions>>,
    /// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
    /// map is equivalent to an element of matchExpressions, whose key field is "key", the
    /// operator is "In", and the values array contains only "value". The requirements are ANDed.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "matchLabels"
    )]
    pub match_labels: Option<BTreeMap<String, String>>,
}

/// A label selector requirement is a selector that contains values, a key, and an operator that
/// relates the key and values.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpAdvertisementAdvertisementsSelectorMatchExpressions {
    /// key is the label key that the selector applies to.
    pub key: String,
    /// operator represents a key's relationship to a set of values.
    /// Valid operators are In, NotIn, Exists and DoesNotExist.
    pub operator: CiliumBgpAdvertisementAdvertisementsSelectorMatchExpressionsOperator,
    /// values is an array of string values. If the operator is In or NotIn,
    /// the values array must be non-empty. If the operator is Exists or DoesNotExist,
    /// the values array must be empty. This array is replaced during a strategic
    /// merge patch.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub values: Option<Vec<String>>,
}

/// A label selector requirement is a selector that contains values, a key, and an operator that
/// relates the key and values.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub enum CiliumBgpAdvertisementAdvertisementsSelectorMatchExpressionsOperator {
    In,
    NotIn,
    Exists,
    DoesNotExist,
}

/// Service defines configuration options for the "Service" advertisementType.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CiliumBgpAdvertisementAdvertisementsService {
    /// Addresses is a list of service address types which needs to be advertised via BGP.
    pub addresses: Vec<String>,
    /// IPv4 mask to aggregate BGP route advertisements of service
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "aggregationLengthIPv4"
    )]
    pub aggregation_length_i_pv4: Option<i64>,
    /// IPv6 mask to aggregate BGP route advertisements of service
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "aggregationLengthIPv6"
    )]
    pub aggregation_length_i_pv6: Option<i64>,
}
