diff --git a/src/ReC.Application/Common/Procedures/EntityType.cs b/src/ReC.Application/Common/Procedures/EntityType.cs new file mode 100644 index 0000000..e1395d7 --- /dev/null +++ b/src/ReC.Application/Common/Procedures/EntityType.cs @@ -0,0 +1,51 @@ +namespace ReC.Application.Common.Procedures; + +/// +/// Represents the target entity type for stored procedure operations (Insert, Update, Delete). +/// +public enum EntityType +{ + /// + /// A scheduled or configured action within a profile that invokes an endpoint (maps to TBREC_CFG_ACTION). + /// + Action, + + /// + /// A REST endpoint URI configuration (maps to TBREC_CFG_ENDPOINT). + /// + Endpoint, + + /// + /// Authentication credentials for an endpoint such as API key, Bearer token, or NTLM (maps to TBREC_CFG_ENDPOINT_AUTH). + /// + EndpointAuth, + + /// + /// Key-value parameters attached to an endpoint (maps to TBREC_CFG_ENDPOINT_PARAMS). + /// + EndpointParams, + + /// + /// A profile that groups one or more actions and defines execution settings (maps to TBREC_CFG_PROFILE). + /// + Profile, + + /// + /// The outcome of an action invocation including HTTP status, headers, body, and error details (maps to TBREC_OUT_RESULT). + /// + Result +} + +public static class EntityTypeExtensions +{ + public static string ToDbString(this EntityType entityType) => entityType switch + { + EntityType.Action => "ACTION", + EntityType.Endpoint => "ENDPOINT", + EntityType.EndpointAuth => "ENDPOINT_AUTH", + EntityType.EndpointParams => "ENDPOINT_PARAMS", + EntityType.Profile => "PROFILE", + EntityType.Result => "RESULT", + _ => throw new ArgumentOutOfRangeException(nameof(entityType), $"Not expected entity type value: {entityType}") + }; +} \ No newline at end of file diff --git a/src/ReC.Application/Common/Procedures/StoredProcedureBuilder.cs b/src/ReC.Application/Common/Procedures/StoredProcedureBuilder.cs index 0815e31..ff3a6ab 100644 --- a/src/ReC.Application/Common/Procedures/StoredProcedureBuilder.cs +++ b/src/ReC.Application/Common/Procedures/StoredProcedureBuilder.cs @@ -1,4 +1,5 @@ using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using System.Data; using System.Text; @@ -30,6 +31,22 @@ internal sealed class StoredProcedureBuilder(string procedureName, string? retur return this; } + public StoredProcedureBuilder Add(string name, EntityType entityType) + { + var entityTypeStr = entityType switch + { + EntityType.Action => "ACTION", + EntityType.Endpoint => "ENDPOINT", + EntityType.EndpointAuth => "ENDPOINT_AUTH", + EntityType.EndpointParams => "ENDPOINT_PARAMS", + EntityType.Profile => "PROFILE", + EntityType.Result => "RESULT", + _ => throw new ArgumentOutOfRangeException(nameof(entityType), $"Not expected entity type value: {entityType}") + }; + + return Add(name, entityTypeStr); + } + public StoredProcedureBuilder AddOutput(string name, SqlDbType dbType) { _execSql.AppendLine($"{_separator}@{name} = @{name} OUTPUT");