Public/New-AMONotifications.ps1

<#
.SYNOPSIS
Creates a new notification.
.DESCRIPTION
This function creates a new notification in the system.
.PARAMETER CreatedBy
Specifies the creator of the notification.
.PARAMETER Title
Specifies the title of the notification.
.PARAMETER Description
Specifies the description of the notification.
.PARAMETER Level
Specifies the level of the notification (Info, Warning, Error, Success).
.PARAMETER DataSourcePath
Specifies the path to the data source.
.EXAMPLE
New-AMONotification -CreatedBy "John" -Title "Notification Title" -Description "Notification Description" -Level "Info"
#>

function New-AMONotification
{
    [CmdletBinding(SupportsShouldProcess)]
    param(
        [string]$CreatedBy,
        [Parameter(Mandatory = $true)]
        [string]$Title,
        [Parameter(Mandatory = $true)]
        [string]$Description,
        [Parameter(Mandatory = $true)]
        [ValidateSet("Info", "Warning", "Error", "Success")]
        [string]$Level,
        [string]$DataSourcePath = "$Repository\..\database.db"
    )

    if ($PSCmdlet.ShouldProcess("Create notification: $Title")) {
        if ($CreatedBy -eq [System.String]::Empty)
        {
            $CreatedBy = "System"
            Write-Verbose "CreatedBy is empty. Setting to 'System'."
        }
        if (-not (Test-Path $DataSourcePath))
        {
            Write-Error "Database not found at $DataSourcePath"
            throw [System.IO.FileNotFoundException]::new("Database not found at $DataSourcePath")
        }
        {
            Write-Error "Database not found at $DataSourcePath"
            throw [System.IO.FileNotFoundException]::new("Database not found at $DataSourcePath")
        }
        $IntLevel = Switch ($Level)
        {
            "Info" { 0 }
            "Warning" { 1 }
            "Error" { 2 }
            "Success" { 3 }
            default { 4 }
        }
        Write-Verbose "Level: $Level -> $IntLevel"

        if ($IntLevel -eq 3)
        {
            $Title = "Success: $Title"
            
        }
        if ($IntLevel -eq 4)
        {
            $Title = "Undefined: $Title"
        }
        $Today = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        Write-Verbose "Making a new notification..."
        Write-Verbose "Title: $Title"
        Write-Verbose "Description: $Description"
        Write-Verbose "Level: $IntLevel"
        Write-Verbose "CreatedBy: $CreatedBy"
        Write-Verbose "CreatedTime: $Today"

        Write-Verbose "Inserting notification..."
        $Query = "INSERT INTO Notification (CreatedBy, CreatedTime, Description, Level, Title, Viewed) VALUES ('System', '$Today', '$Description', '$IntLevel', '$Title', '0')"
        Write-Verbose "Query: $Query"
        Invoke-SqliteQuery -DataSource $DataSourcePath -Query $Query -ErrorAction Stop
        Write-Verbose "Notification inserted."
    }
}