Public/WorkTickets/New-AspireWorkTicketsCreateAsNeededWorkTickets.ps1

<#
.SYNOPSIS
    Creates as needed work tickets from the Aspire API.
.DESCRIPTION
    Uses Invoke-AspireRequest to perform a POST request to the /WorkTickets/CreateAsNeededWorkTickets endpoint.
.PARAMETER OpportunityServiceId
    The ID of the opportunity service (integer).
.PARAMETER RouteId
    The ID of the route (integer).
.PARAMETER ScheduledStartDate
    The scheduled start date (required, date-time string).
.PARAMETER StartDateTime
    The start date time (date-time string).
.PARAMETER EndDateTime
    The end date time (date-time string).
.PARAMETER HoursPerDay
    The hours per day (double).
.OUTPUTS
    The response from the API.
.EXAMPLE
    New-AspireWorkTicketsCreateAsNeededWorkTickets -ScheduledStartDate "2023-01-01T00:00:00Z"
#>

function New-AspireWorkTicketsCreateAsNeededWorkTickets {
    [CmdletBinding()]
    param(
        [int]$OpportunityServiceId = $null,
        [int]$RouteId = $null,
        [Parameter(Mandatory = $true)]
        [string]$ScheduledStartDate,
        [string]$StartDateTime = $null,
        [string]$EndDateTime = $null,
        [double]$HoursPerDay = $null
    )

    $body = @{
        ScheduledStartDate = $ScheduledStartDate
    }
    if ($OpportunityServiceId) {
        $body.OpportunityServiceId = $OpportunityServiceId
    }
    if ($RouteId) {
        $body.RouteId = $RouteId
    }
    if ($StartDateTime) {
        $body.StartDateTime = $StartDateTime
    }
    if ($EndDateTime) {
        $body.EndDateTime = $EndDateTime
    }
    if ($HoursPerDay) {
        $body.HoursPerDay = $HoursPerDay
    }

    return Invoke-AspireRequest -Method POST -Path "/WorkTickets/CreateAsNeededWorkTickets" -Body $body
}