using GB5Shared.DTO.Framework.Login;
using static GB5Shared.DTO.WorkFlow.ContractsDTO;
namespace BizProcessBLL.Interfaces
{
///
/// Seam between BizProcessBLL and whatever system actually holds live operational data
/// (workflow/approval state, document traceability, open-transaction counts) for a
/// process's stages — see the plan's "Standalone-Readiness" section. Only a GB5
/// implementation () exists today; the seam
/// means a future non-GB5 source system wouldn't require redesigning BizProcessBLL.
///
public interface IProcessOperationalDataSource
{
///
/// Whether an approval workflow is configured for the given document context, and if so,
/// which MWORKFLOW row. Returns null on any failure to reach the workflow engine — a
/// missing/unreachable workflow config should never block rendering the process map.
/// Resolves the real MENTITY.ENTITYID from bizTransactionClassId internally (via
/// MBIZTRANSACTIONCLASS.ENTITYID) rather than taking it as a parameter — every real
/// MWORKFLOWCONFIG row on GB5DEMO turned out to be entity-scoped (never -1/wildcard), so
/// skipping this resolution would make the lookup silently never match anything real.
///
Task GetWorkflowConfigAsync(
int bizTransactionClassId, int bizTransactionId, LoginDTO login, CancellationToken ct);
/// Steps (approval levels) of a resolved workflow, for the click-through detail panel.
Task> GetWorkflowStepsAsync(int workflowId, LoginDTO login, CancellationToken ct);
///
/// The real, ordered document chain around a pivot TALLOCATION row (both directions),
/// for Phase 7's instance-traceability view. Returns an empty sequence on any failure to
/// reach the source system or when the pivot doesn't resolve — a broken trace read must
/// never block the rest of the process map from rendering.
///
Task> GetDocumentTraceAsync(int pivotAllocationId, LoginDTO login, CancellationToken ct);
///
/// Open-document count per BizTransactionTypeId, for Phase 8's open-documents dashboard.
/// Type-level (not class-level, despite the plan's original sketch) because that's the
/// real granularity MM's TPENDINGALLOCATION tracks and BizProcessStage itself links on.
/// Returns an empty sequence on any failure -- a broken open-count read must never block
/// the rest of the process map from rendering.
///
Task> GetOpenCountsAsync(IEnumerable bizTransactionTypeIds, LoginDTO login, CancellationToken ct);
}
/// One MM TPENDINGALLOCATION aggregate row -- see GetPendingCountsByTransactionType.
public class StageOpenCountDTO
{
public int BizTransactionTypeId { get; set; } = -1;
public int OpenCount { get; set; }
}
///
/// Trimmed-down view of MM's DocumentTraceabilityDTO — only what BizProcess needs to bucket a
/// chain into visited/current/future stages. DocumentLevel is signed relative to the pivot:
/// 0 = the pivot row itself, <0 = predecessor documents, >0 = successor documents that
/// already exist (both directions only contain rows for allocations that were actually
/// created, per TALLOCATION.ALLOTEDALLOCATIONID chain-walking).
///
public class DocumentTraceRowDTO
{
public int AllocationId { get; set; }
public int ParentAllocationId { get; set; }
public int DocumentLevel { get; set; }
public int BizTransactionTypeId { get; set; } = -1;
public string? DocumentNumber { get; set; }
public DateTime DocumentDate { get; set; }
// Entity Viewer drill-through (confirmed live against GB5DEMO 2026-08-30):
// ObjectHeaderTypeId is already a real MENTITY.ENTITYID (e.g. MMHEAD), and
// ObjectHeaderId is that entity's own PK -- no BizTransactionTypeId->EntityId
// resolution needed here, unlike the workflow lookup (a different question:
// "what entity does this class's workflow apply to", not "what entity is this
// row"). ObjectTypeId/ObjectId (deliberately not carried here) resolve one level
// lower, to the document's line-item entity (e.g. MMDETAIL), not the document itself.
public int ObjectHeaderTypeId { get; set; } = -1;
public int ObjectHeaderId { get; set; } = -1;
}
/// Trimmed-down view of — only what BizProcess needs.
public class WorkflowLookupResult
{
public bool IsEnabled { get; set; }
public int WorkFlowId { get; set; }
}
///
/// One MWORKFLOWDETAIL row, trimmed to what the approval-detail panel shows. Loosely typed
/// on the source side (GetWorkflow's real backing DTO lives in the Framework host and isn't
/// referenced directly — see Gb5ProcessOperationalDataSource's own comment on why).
///
public class WorkflowStepSummaryDTO
{
public int ApprovalLevel { get; set; }
public string? DisplayName { get; set; }
public int StepType { get; set; }
public string? ParallelGroupKey { get; set; }
public string? EvalCondition { get; set; }
}
}