function CheckCdnEndpoints() {
    param(
    [Parameter(Mandatory)]
     [Microsoft.Azure.Commands.Profile.Models.Core.PSAzureContext]$subscription,
     [Parameter(Mandatory)]
     [Microsoft.Azure.Commands.Cdn.Models.Profile.PSProfile[]] $cdnProfiles,
     [Parameter(Mandatory)]
     [string]$effectoryDomainPattern
    )
    [EffectoryDomainNameCheck[]]$Result = @()
    
    foreach($cdnProfile in $cdnProfiles) {
        $cdnEndPoints = Get-AzCdnEndpoint -ProfileName $cdnProfile.Name -ResourceGroupName $cdnProfile.ResourceGroupName
        foreach($cdnEndPoint in $cdnEndPoints) {
            $resource = Get-AzResource -ResourceId $cdnEndPoint.Id
            $cdnEffectory = Get-AzCdnCustomDomain -CdnEndpoint $cdnEndPoint | Where-Object HostName -Like $effectoryDomainPattern

            foreach($cdn in $cdnEffectory) {
                $domainNameCheck = [EffectoryDomainNameCheck] @{
                    SubscriptionId = $subscriptionId; 
                    SubscriptionName = $subscription.Name;
                    ResourceId = $cdn.Id;
                    ResourceName = $cdn.Name;
                    ResourceType = $cdn.Type;
                    ResourceGroupName = $cdn.ResourceGroupName;
                    DomainName = $cdn.HostName;
                    Tag_Team = $resource.Tags.team
                    Tag_Product = $resource.Tags.product
                    Tag_Environment = $resource.Tags.environment
                    Tag_Data = $resource.Tags.data
                }
                $Result += $domainNameCheck
            }
        }
    }

    $Result
}

