71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using C4IT.FASD.Cockpit.Communication;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace FasdCockpitCommunication.TicketOverview
|
|
{
|
|
internal sealed class TicketOverviewCountsResponse
|
|
{
|
|
[JsonProperty("counts")]
|
|
public Dictionary<string, int> Counts { get; set; } = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
[JsonProperty("capabilities")]
|
|
public TicketOverviewCapabilitiesResponse Capabilities { get; set; } = new TicketOverviewCapabilitiesResponse();
|
|
|
|
public cF4sdTicketOverviewCountsResult ToResult(IEnumerable<string> expectedKeys)
|
|
{
|
|
var comparer = StringComparer.OrdinalIgnoreCase;
|
|
var output = new Dictionary<string, int>(comparer);
|
|
|
|
if (expectedKeys != null)
|
|
{
|
|
foreach (var key in expectedKeys)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(key))
|
|
continue;
|
|
|
|
if (Counts != null && Counts.TryGetValue(key, out var count))
|
|
output[key] = count;
|
|
else
|
|
output[key] = 0;
|
|
}
|
|
|
|
return CreateResult(output);
|
|
}
|
|
|
|
if (Counts != null)
|
|
{
|
|
foreach (var kvp in Counts)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(kvp.Key))
|
|
continue;
|
|
|
|
output[kvp.Key] = kvp.Value;
|
|
}
|
|
}
|
|
|
|
return CreateResult(output);
|
|
}
|
|
|
|
private cF4sdTicketOverviewCountsResult CreateResult(Dictionary<string, int> counts)
|
|
{
|
|
return new cF4sdTicketOverviewCountsResult
|
|
{
|
|
Counts = counts,
|
|
Capabilities = new cF4sdTicketOverviewCapabilities
|
|
{
|
|
TicketAndServiceRequestsEnabled = Capabilities?.TicketAndServiceRequestsEnabled ?? true
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
internal sealed class TicketOverviewCapabilitiesResponse
|
|
{
|
|
[JsonProperty("ticketAndServiceRequestsEnabled")]
|
|
public bool TicketAndServiceRequestsEnabled { get; set; } = true;
|
|
}
|
|
}
|