using qdr.fnd.core.pqueue.Enums;
using Quadarax.Foundation.Core.Data;
namespace qdr.fnd.core.pqueue.Storages
{
///
/// PsQueue persistence storage interface. Manipulates with entities.
///
/// Has no any business logic. Just a storage interface.
/// Throws directly exceptions if something goes wrong.
///
///
public interface IPsQueueStorage : IDisposable
{
#region *** Operations ***
#region **** Transactions ****
///
/// Creates a new transaction and returns its id
///
/// Transaction identifier
public string CreateTransaction();
///
/// Commits all changes on the transaction specified by the and closes transaction.
///
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier
public void CommitTransaction(string transactionId);
///
/// Rollbacks all changes on the transaction specified by the and closes transaction.
///
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier
public void RollbackTransaction(string transactionId);
#endregion
#region **** Items ****
///
/// Creates a new item in the queue storage and returns its identifier.
///
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Owner identifier
/// Owner reference identifier
/// Process provider qualified type name
/// Timestamp when record will be created. If null use current datetime.
/// Item identifier.
public string CreateItem(string transactionId, string owner, string ownerRef, string providerClass, DateTime? created);
///
/// Deletes (force) the item (and all related entities) specified by the no matter what status item has.
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
public void DeleteItem(string transactionId, string itemId);
///
/// Updates the priority of the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// Process priority value.
public void UpdateItemPriority(string transactionId, string itemId, int priority);
///
/// Updates the validity of the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// Timestamp for validFrom value.
/// Timespamp for validTo value.
public void UpdateItemValidity(string transactionId, string itemId, DateTime validForm, DateTime? validTo);
///
/// Updates the status of the item specified by the . Doesn't affects the status journal or logs.
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
/// Doesn't validate the status transitions. Force update.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// New item status. If null status will be kept.
/// New transient flag.
public void UpdateItemStatus(string transactionId, string itemId, PsStatusEnum? status, bool isTransient);
///
/// Updates the attempts left value of the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
/// Doesn't validate attempts counter. Force update.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// New attempt value.
public void UpdateItemAttempts(string transactionId, string itemId, int attemptsLeft);
///
/// Updates the process started timestamp of the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// New timestamp value or null.
public void UpdateItemStarted(string transactionId, string itemId, DateTime? started);
///
/// Updates the process finished timestamp of the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// New timestamp value or null.
public void UpdateItemFinished(string transactionId, string itemId, DateTime? finished);
#endregion
#region **** Item Attributes ****
///
/// Creates a new item attribute with the specified and for the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
/// If already exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// Unique attribute name in scope.
/// Value serialized as string or null.
/// Value type qualified class name.
/// Flag defines if attribute is input/output.
public void CreateItemAttribute(string transactionId, string itemId, string name, string? value, string valueTypeClass,bool isOutput);
///
/// Updates the value of the item attribute specified by the for the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// Unique attribute name in scope.
/// Value serialized as string or null.
public void UpdateItemAttribute(string transactionId, string itemId, string name, string value);
///
/// Deletes the item attribute specified by the for the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// Unique attribute name in scope.
public void DeleteItemAttribute(string transactionId, string itemId, string name);
#endregion
#region **** Item Collections ****
///
/// Appends a new log record to the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// Log message.
/// Message code
/// Message type
public void AppendLog(string transactionId, string itemId, string message, int code, ErrorLevelEnum messageType);
///
/// Appends a new status journal record to the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation.
/// Item identifier.
/// Previous status.
/// Previous isTransient flag.
/// Message.
public void AppendStatusJournal(string transactionId, string itemId, PsStatusEnum status, bool isTransient, string message);
#endregion
#region **** Queries & Get ****
///
/// Returns collection of process item by input conditions.
///
/// Query items outside the transaction scope (must be committed).
///
///
/// Owner identifier. If null then condition is skipped.
/// Owner reference identifier. If null then condition is skipped.
/// Collection of requested complex statuses (isTransient, Status).
/// Queryable collection of requested items.
public IQueryable Query(string? owner, string? ownerRef, params Tuple[] status);
///
/// Gets the item specified by the .
///
/// If not exists, the method should throw an exception.
/// If not exists, the method should throw an exception.
///
///
/// Transaction identifier generated by operation. If null works outside transaction scope.
/// Item identifier.
/// Requested item.
public IPsQueueItem GetItem(string? transactionId, string itemId);
#endregion
#endregion
}
}