BotSharp/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs
2025-03-14 11:13:13 -05:00

62 lines
2.2 KiB
C#

using BotSharp.Abstraction.Functions.Models;
using System.Text.Json;
namespace BotSharp.Plugin.MongoStorage.Models;
[BsonIgnoreExtraElements(Inherited = true)]
public class FunctionDefMongoElement
{
public string Name { get; set; } = default!;
public string Description { get; set; } = default!;
public List<string>? Channels { get; set; }
public string? VisibilityExpression { get; set; }
public string? Impact { get; set; }
public FunctionParametersDefMongoElement Parameters { get; set; } = new();
public string? Output { get; set; }
public static FunctionDefMongoElement ToMongoElement(FunctionDef function)
{
return new FunctionDefMongoElement
{
Name = function.Name,
Description = function.Description,
Channels = function.Channels,
VisibilityExpression = function.VisibilityExpression,
Impact = function.Impact,
Parameters = new FunctionParametersDefMongoElement
{
Type = function.Parameters.Type,
Properties = JsonSerializer.Serialize(function.Parameters.Properties),
Required = function.Parameters.Required,
},
Output = function.Output
};
}
public static FunctionDef ToDomainElement(FunctionDefMongoElement function)
{
return new FunctionDef
{
Name = function.Name,
Description = function.Description,
Channels = function.Channels,
VisibilityExpression = function.VisibilityExpression,
Impact = function.Impact,
Parameters = new FunctionParametersDef
{
Type = function.Parameters.Type,
Properties = JsonSerializer.Deserialize<JsonDocument>(function.Parameters.Properties.IfNullOrEmptyAs("{}")),
Required = function.Parameters.Required,
},
Output = function.Output
};
}
}
public class FunctionParametersDefMongoElement
{
public string Type { get; set; } = default!;
public string Properties { get; set; } = default!;
public List<string> Required { get; set; } = [];
}