BotSharp/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs

62 lines
2.2 KiB
C#
Raw Normal View History

using BotSharp.Abstraction.Functions.Models;
using System.Text.Json;
namespace BotSharp.Plugin.MongoStorage.Models;
2025-02-08 21:49:26 +00:00
[BsonIgnoreExtraElements(Inherited = true)]
public class FunctionDefMongoElement
{
public string Name { get; set; } = default!;
public string Description { get; set; } = default!;
2024-08-13 22:37:47 +00:00
public List<string>? Channels { get; set; }
2024-04-01 04:55:13 +00:00
public string? VisibilityExpression { get; set; }
2023-10-25 18:02:50 +00:00
public string? Impact { get; set; }
public FunctionParametersDefMongoElement Parameters { get; set; } = new();
2025-03-14 16:13:13 +00:00
public string? Output { get; set; }
public static FunctionDefMongoElement ToMongoElement(FunctionDef function)
{
return new FunctionDefMongoElement
{
Name = function.Name,
Description = function.Description,
2024-08-13 22:37:47 +00:00
Channels = function.Channels,
2024-04-01 04:55:13 +00:00
VisibilityExpression = function.VisibilityExpression,
2023-10-25 18:02:50 +00:00
Impact = function.Impact,
Parameters = new FunctionParametersDefMongoElement
{
Type = function.Parameters.Type,
Properties = JsonSerializer.Serialize(function.Parameters.Properties),
Required = function.Parameters.Required,
2025-03-14 16:13:13 +00:00
},
Output = function.Output
};
}
2024-08-13 22:37:47 +00:00
public static FunctionDef ToDomainElement(FunctionDefMongoElement function)
{
return new FunctionDef
{
2024-08-13 22:37:47 +00:00
Name = function.Name,
Description = function.Description,
Channels = function.Channels,
VisibilityExpression = function.VisibilityExpression,
Impact = function.Impact,
Parameters = new FunctionParametersDef
{
2024-08-13 22:37:47 +00:00
Type = function.Parameters.Type,
Properties = JsonSerializer.Deserialize<JsonDocument>(function.Parameters.Properties.IfNullOrEmptyAs("{}")),
Required = function.Parameters.Required,
2025-03-14 16:13:13 +00:00
},
Output = function.Output
};
}
}
public class FunctionParametersDefMongoElement
{
public string Type { get; set; } = default!;
public string Properties { get; set; } = default!;
public List<string> Required { get; set; } = [];
}