Public/WorkTicketTimes/New-AspireWorkTicketTimes.ps1

<#
.SYNOPSIS
    Creates a new work ticket time entry in the Aspire API.
.DESCRIPTION
    Uses Invoke-AspireRequest to perform a POST request to the /WorkTicketTimes endpoint.
.PARAMETER ContactID
    The ID of the contact (integer).
.PARAMETER WorkTicketID
    The ID of the work ticket (integer).
.PARAMETER StartTime
    The start time (required, date-time string).
.PARAMETER StartLatitude
    The start latitude (decimal).
.PARAMETER StartLongitude
    The start longitude (decimal).
.PARAMETER RouteID
    The ID of the route (integer).
.PARAMETER CrewLeaderContactID
    The ID of the crew leader contact (integer).
.PARAMETER EndTime
    The end time (required, date-time string).
.PARAMETER EndLatitude
    The end latitude (decimal).
.PARAMETER EndLongitude
    The end longitude (decimal).
.OUTPUTS
    The response from the API.
.EXAMPLE
    New-AspireWorkTicketTimes -WorkTicketID 123 -StartTime "2023-01-01T08:00:00Z" -EndTime "2023-01-01T17:00:00Z"
#>

function New-AspireWorkTicketTimes {
    [CmdletBinding()]
    param(
        [int]$ContactID = $null,
        [int]$WorkTicketID = $null,
        [Parameter(Mandatory = $true)]
        [string]$StartTime,
        [decimal]$StartLatitude = $null,
        [decimal]$StartLongitude = $null,
        [int]$RouteID = $null,
        [int]$CrewLeaderContactID = $null,
        [Parameter(Mandatory = $true)]
        [string]$EndTime,
        [decimal]$EndLatitude = $null,
        [decimal]$EndLongitude = $null
    )

    $body = @{
        StartTime = $StartTime
        EndTime = $EndTime
    }
    if ($ContactID) {
        $body.ContactID = $ContactID
    }
    if ($WorkTicketID) {
        $body.WorkTicketID = $WorkTicketID
    }
    if ($StartLatitude) {
        $body.StartLatitude = $StartLatitude
    }
    if ($StartLongitude) {
        $body.StartLongitude = $StartLongitude
    }
    if ($RouteID) {
        $body.RouteID = $RouteID
    }
    if ($CrewLeaderContactID) {
        $body.CrewLeaderContactID = $CrewLeaderContactID
    }
    if ($EndLatitude) {
        $body.EndLatitude = $EndLatitude
    }
    if ($EndLongitude) {
        $body.EndLongitude = $EndLongitude
    }

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