Class/UpdateContainersContainerDeviceDefinition.Class.psm1

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

## Container Device Definition Class.
class UpdateContainersContainerDeviceDefinition
{
    <#
    .NAME
        UpdateContainersContainerDeviceDefinition

    .SYNOPSIS
        Class defining a device mapping for container engines.

    .DESCRIPTION
        This class represents a device mapping that can be applied to containers
        managed by container engines like Docker and Podman.

    .PROPERTIES
        Destination
            The path inside the container where the device will be mapped.

        Source
            The path on the host system of the device to be mapped.
    #>


    ## Destination Property.
    [AllowNull()]
    [JsonPropertyName('destination')]
    [String] $Destination = $null;

    ## Source Property.
    [JsonPropertyName('source')]
    [JsonRequired()]
    [String] $Source;

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

        .SYNOPSIS
            Generates the command line string for the device mapping.

        .DESCRIPTION
            This method constructs the appropriate command line string to map
            a device into a container using the specified source and destination
            paths defined in the ContainerDeviceDefinition class.

        .OUTPUTS
            String
                The command line string for the device mapping.
        #>


        ## Define our command line string.
        [String] $command = "--device '$($this.Source.Trim())";

        ## Check for a provided source.
        if ($null -ne $this.Destination -and "" -ne $this.Destination.Trim())
        {
            ## Append the source to the command line string.
            $command = "${command}:$($this.Source.Trim())";
        }

        ## We're done, return the command line string.
        return "${command}'".Trim();
    }
};