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

69 lines
2.1 KiB
C#
Raw Normal View History

using BotSharp.Abstraction.Functions.Models;
using System.Text.Json;
namespace BotSharp.Plugin.MongoStorage.Models;
2023-10-25 20:09:21 +00:00
[BsonIgnoreExtraElements]
public class FunctionDefMongoElement
{
public string Name { get; set; }
public string Description { get; set; }
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 FunctionParametersDefMongoElement();
public FunctionDefMongoElement()
{
}
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,
}
};
}
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,
}
};
}
}
public class FunctionParametersDefMongoElement
{
public string Type { get; set; }
public string Properties { get; set; }
public List<string> Required { get; set; } = new List<string>();
public FunctionParametersDefMongoElement()
{
}
}