Class/UpdateContainersContainerNetworkRouteDefinition.Class.psm1

## Namespaces.
using namespace System.Text.Json;
using namespace System.Text.Json.Serialization;

## Container Network Route Definition Class.
class UpdateContainersContainerNetworkRouteDefinition
{
    <#
    .NAME
        UpdateContainersContainerNetworkRouteDefinition

    .SYNOPSIS
        Class defining a network route configuration for container engines.

    .DESCRIPTION
        This class represents the configuration details for a network route that can be
        applied to containers managed by container engines like Docker and Podman.

    .PROPERTIES
        Destination
            The destination CIDR for the route (e.g., "192.168.3.0/24").

        Gateway
            The gateway IP address for the route (e.g., "192.168.3.1").
    #>


    ## Destination Property.
    [JsonPropertyName('destination')]
    [JsonRequired()]
    [String] $Destination;

    ## Gateway Property.
    [JsonPropertyName('gateway')]
    [JsonRequired()]
    [String] $Gateway;

    ## ToCommandLine Method.
    [String] ToCommandLine([String] $interface)
    {
        <#
        .NAME
            ToCommandLine

        .SYNOPSIS
            Generates the command line string for the network route configuration.

        .DESCRIPTION
            This method constructs the appropriate command line string to define
            a network route for a container using the properties defined in the
            ContainerNetworkRouteDefinition class.

        .PARAMETERS
            interface
                The network interface to which the route applies.

                Required? true

        .OUTPUTS
            String
                The command line string for the network route configuration.
        #>


        ## Define and return our command line string.
        return "ip route add '$($this.Destination.Trim())' via '$($this.Gateway.Trim())' dev '$($interface.Trim())'";
    }
};