using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Altinn.Platform.Events.Models
{
///
/// Class that describes an events subscription
///
public class Subscription
{
///
/// Subscription Id
///
public int Id { get; set; }
///
/// Endpoint to receive matching events
///
public Uri EndPoint { get; set; }
///
/// Filter on source
///
public Uri SourceFilter { get; set; }
///
/// Filter on resource
///
public string ResourceFilter { get; set; }
///
/// Filter on subject
///
public string SubjectFilter { get; set; }
///
/// Filter on alternative subject
///
public string AlternativeSubjectFilter { get; set; }
///
/// Filter for type. The different sources has different types.
///
public string TypeFilter { get; set; }
///
/// The events consumer
///
public string Consumer { get; set; }
///
/// Who created this subscription
///
public string CreatedBy { get; set; }
///
/// When subscription was created
///
public DateTime Created { get; set; }
///
/// Indicate whether the subscription has been validated to be ok.
///
public bool Validated { get; set; }
///
/// Serializes the subscription to a JSON string.
///
/// Serialized cloud event
public string Serialize()
{
return JsonSerializer.Serialize(this, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull });
}
///
/// Deserializes the subscription from a JSON string.
///
/// Cloud event
public static Subscription Deserialize(string jsonString)
{
return JsonSerializer.Deserialize(jsonString, new JsonSerializerOptions { });
}
}
}