// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Microsoft.Teams.Apps.Schema;
using Microsoft.Teams.Core.Schema;
namespace Microsoft.Teams.Apps.Handlers;
///
/// Represents an event activity.
///
public class EventActivity : TeamsActivity
{
///
/// Creates an EventActivity from a CoreActivity.
///
public static new EventActivity FromActivity(CoreActivity activity)
{
ArgumentNullException.ThrowIfNull(activity);
return new EventActivity(activity);
}
///
/// Gets or sets the name of the event. See for common values.
///
[JsonPropertyName("name")]
public string? Name { get; set; }
///
/// Gets or sets the value payload of the event activity.
///
[JsonPropertyName("value")]
public JsonNode? Value { get; set; }
///
/// Initializes a new instance of the class.
///
[JsonConstructor]
internal EventActivity() : base(TeamsActivityTypes.Event)
{
}
///
/// Initializes a new instance of the class from a CoreActivity.
///
internal EventActivity(CoreActivity activity) : base(activity)
{
Name = activity.Properties.Extract("name");
Value = activity is EventActivity evt
? evt.Value
: activity.Properties.Extract("value");
}
}
///
/// Represents an event activity with a strongly-typed value.
///
/// The type of the value payload.
public class EventActivity : EventActivity
{
///
/// Gets or sets the strongly-typed value associated with the event activity.
/// Shadows the base class Value property, deserializing from the underlying JsonNode on access.
///
public new TValue? Value
{
get => base.Value != null ? JsonSerializer.Deserialize(base.Value.ToJsonString()) : default;
set => base.Value = value != null ? JsonSerializer.SerializeToNode(value) : null;
}
///
/// Initializes a new instance of the class.
///
internal EventActivity() : base()
{
}
///
/// Initializes a new instance of the class from an EventActivity.
///
internal EventActivity(EventActivity activity) : base(activity)
{
}
}
///
/// String constants for event activity names.
///
public static class EventNames
{
/// Meeting start event name.
public const string MeetingStart = "application/vnd.microsoft.meetingStart";
/// Meeting end event name.
public const string MeetingEnd = "application/vnd.microsoft.meetingEnd";
/// Meeting participant join event name.
public const string MeetingParticipantJoin = "application/vnd.microsoft.meetingParticipantJoin";
/// Meeting participant leave event name.
public const string MeetingParticipantLeave = "application/vnd.microsoft.meetingParticipantLeave";
}