using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using FrameworkDAL.Query.SIP; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.SIP; using GB5Shared.Validation; namespace FrameworkDAL.CustomCode.SIP { public class SIPPatternEntryDAL : ISIPPatternEntryDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public SIPPatternEntryDAL(IQueryExecutor QueryExecutor, IValidation Validation) { _QueryExecutor = QueryExecutor; _Validation = Validation; } public async Task InsertPatternEntry(PatternEntryDTO dto, LoginDTO login, CancellationToken ct) { try { var detectedOn = dto.DetectedOn == default ? DateTime.UtcNow : dto.DetectedOn; // TSIPPATTERNENTRY is an immutable, append-only ledger — plain insert, no identity // read-back needed by any current caller (ISIPSignalService.EmitSignalAsync returns // Task, not the new row's ID). await _QueryExecutor.ExecuteAsync( login, SIPPatternEntryQB.INSERT_PATTERN_ENTRY, new { ClientId = login.ClientId, dto.Domain, dto.EntityCode, dto.EntityId, dto.SignalType, dto.Detail, dto.Strength, dto.ActorRole, dto.ActorId, DetectedOn = detectedOn }); } catch (Exception ex) { throw new Exception(await _Validation.HandleException(ex, ErrorResponse.SaveErrorMessage)); } } public async Task> GetPatternSummary( string domain, string entityCode, int entityId, LoginDTO login, CancellationToken ct) { try { return await _QueryExecutor.QueryAsync( login, SIPPatternEntryQB.GET_PATTERN_SUMMARY, new { ClientId = login.ClientId, Domain = domain, EntityCode = entityCode, EntityId = entityId }); } catch (Exception ex) { throw new Exception(await _Validation.HandleException(ex, ErrorResponse.GetFetchingMessge)); } } } }