package com.pablotj.ai.chat.domain.repository;

import com.pablotj.ai.chat.domain.model.Conversation;
import com.pablotj.ai.chat.domain.model.ConversationId;
import com.pablotj.ai.chat.domain.model.ConversationStatus;
import java.util.List;
import java.util.Optional;

/**
 * Repository interface for conversation persistence operations.
 * Defines the contract for conversation data access in the domain layer.
 */
public interface ConversationRepository {

    /**
     * Saves a conversation to the repository.
     *
     * @param conversation the conversation to save
     * @return the saved conversation
     */
    Conversation save(Conversation conversation);

    /**
     * Finds a conversation by its unique identifier.
     *
     * @param conversationId the conversation identifier
     * @return an optional containing the conversation if found
     */
    Optional<Conversation> findById(ConversationId conversationId);

    /**
     * Finds all conversations with the specified status.
     *
     * @param status the conversation status to filter by
     * @return list of conversations with the specified status
     */
    List<Conversation> findByStatus(ConversationStatus status);

    /**
     * Finds all active conversations ordered by creation date (newest first).
     *
     * @return list of active conversations
     */
    List<Conversation> findAllActiveOrderedByCreationDate();

    /**
     * Checks if a conversation exists with the given identifier.
     *
     * @param conversationId the conversation identifier
     * @return true if the conversation exists, false otherwise
     */
    boolean existsById(ConversationId conversationId);

    /**
     * Deletes a conversation by its identifier.
     *
     * @param conversationId the conversation identifier
     */
    void deleteById(ConversationId conversationId);

    /**
     * Counts the total number of conversations.
     *
     * @return the total count of conversations
     */
    long count();

    /**
     * Counts conversations by status.
     *
     * @param status the conversation status
     * @return the count of conversations with the specified status
     */
    long countByStatus(ConversationStatus status);
}
