using System.Collections.Generic;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using GB5Shared.DTO.Draft;
using GB5Shared.DTO.Framework.Login;
namespace GB5Shared.Draft
{
public interface IDraftRowDAL
{
/// Returns 0 if no draft exists for this session.
Task GetDraftIdBySessionAsync(string sessionGuid, LoginDTO login, CancellationToken ct);
/// Returns the draft header for the given session, or null if not found.
Task GetDraftHeaderAsync(string sessionGuid, LoginDTO login, CancellationToken ct);
///
/// MERGE-upserts the draft header. @draftId must be pre-allocated
/// by the BLL via AutoNumber for new sessions (0 = not yet allocated
/// means the caller checks first). Returns the actual DraftId stored.
///
Task UpsertHeaderAsync(DraftSessionDTO dto, int draftId, LoginDTO login, CancellationToken ct);
///
/// MERGE-upserts one dirty row into TDRAFT_ROWS.
/// RowState=Unchanged and RowState=Deleted must be rejected by the BLL before this is called.
///
Task UpsertRowAsync(DraftRowDTO dto, LoginDTO login, CancellationToken ct);
///
/// Hard-deletes a single row from TDRAFT_ROWS by SessionGuid + RowGuid.
/// Called by the BLL when RowState=Deleted arrives on UpsertRow.
///
Task DeleteRowAsync(string sessionGuid, Guid rowGuid, LoginDTO login, CancellationToken ct);
/// Returns all dirty rows for a session ordered for tree reconstruction.
Task> GetDraftRowsAsync(string sessionGuid, LoginDTO login, CancellationToken ct);
/// Returns draft pool items (Active/Suspended/Transferred) for menu + user.
Task> GetDraftPoolAsync(int menuId, LoginDTO login, CancellationToken ct);
///
/// Deletes TDRAFT_ROWS then TDRAFT for the session.
/// tx is optional — pass when called inside an entity save transaction.
///
Task CleanupAsync(string sessionGuid, byte actionType, LoginDTO login, DbTransaction? tx, CancellationToken ct);
///
/// Transfers draft to targetUserId. SP validates ownership at DB level.
/// Application-layer ownership check should precede this call.
///
Task ShareAsync(DraftShareDTO dto, LoginDTO login, CancellationToken ct);
/// Returns count of sessions expired and deleted in this batch.
Task CleanupOrphansAsync(int retentionHours, int batchSize, LoginDTO login, CancellationToken ct);
/// Returns 1 if the session exists and requesting user is the owner.
Task CheckOwnershipAsync(string sessionGuid, LoginDTO login, CancellationToken ct);
}
}