using FacebookService.Domain.SeedWork;

namespace FacebookService.Domain.AggregatesModel.ChatbotAggregate;

/// <summary>
/// EN: Repository interface for ChatbotFlow aggregate.
/// VI: Interface repository cho ChatbotFlow aggregate.
/// </summary>
public interface IChatbotFlowRepository : IRepository<ChatbotFlow>
{
    /// <summary>
    /// EN: Get flow by ID with nodes.
    /// VI: Lấy flow theo ID với nodes.
    /// </summary>
    Task<ChatbotFlow?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Get flow by ID including all nodes.
    /// VI: Lấy flow theo ID bao gồm tất cả nodes.
    /// </summary>
    Task<ChatbotFlow?> GetByIdWithNodesAsync(Guid id, CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Get all flows for a shop.
    /// VI: Lấy tất cả flows của một shop.
    /// </summary>
    Task<IReadOnlyList<ChatbotFlow>> GetByShopIdAsync(Guid shopId, CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Find matching active flow by trigger.
    /// VI: Tìm flow đang hoạt động khớp trigger.
    /// </summary>
    Task<ChatbotFlow?> FindActiveByTriggerAsync(
        Guid shopId,
        FlowTriggerType triggerType,
        string triggerValue,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Check if trigger value exists for shop.
    /// VI: Kiểm tra giá trị trigger có tồn tại cho shop.
    /// </summary>
    Task<bool> ExistsByTriggerValueAsync(
        Guid shopId,
        string triggerValue,
        Guid? excludeFlowId = null,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Add a new flow.
    /// VI: Thêm flow mới.
    /// </summary>
    ChatbotFlow Add(ChatbotFlow flow);

    /// <summary>
    /// EN: Update an existing flow.
    /// VI: Cập nhật flow hiện có.
    /// </summary>
    void Update(ChatbotFlow flow);

    /// <summary>
    /// EN: Delete a flow.
    /// VI: Xóa flow.
    /// </summary>
    void Delete(ChatbotFlow flow);
}
