package com.social.media.domain.socialaccount.repository;

import com.social.media.domain.socialaccount.aggregate.SocialAccount;
import com.social.media.domain.socialaccount.valueobject.SocialAccountId;
import com.social.media.domain.socialaccount.valueobject.ConnectionStatus;
import com.social.media.domain.user.valueobject.UserId;
import com.social.media.domain.company.valueobject.CompanyId;
import com.social.media.domain.socialnetwork.valueobject.SocialNetworkId;

import java.util.List;
import java.util.Optional;

/**
 * Repository interface for SocialAccount aggregate
 * This is a port in the hexagonal architecture
 */
public interface SocialAccountRepository {
    
    /**
     * Save a social account (create or update)
     */
    SocialAccount save(SocialAccount socialAccount);
    
    /**
     * Find social account by ID
     */
    Optional<SocialAccount> findById(SocialAccountId id);
    
    /**
     * Find social accounts by user
     */
    List<SocialAccount> findByUserId(UserId userId);
    
    /**
     * Find social accounts by company
     */
    List<SocialAccount> findByCompanyId(CompanyId companyId);
    
    /**
     * Find social accounts by social network
     */
    List<SocialAccount> findBySocialNetworkId(SocialNetworkId socialNetworkId);
    
    /**
     * Find social account by platform account ID and social network
     */
    Optional<SocialAccount> findByPlatformAccountIdAndSocialNetworkId(String platformAccountId, SocialNetworkId socialNetworkId);
    
    /**
     * Find social accounts by status
     */
    List<SocialAccount> findByConnectionStatus(ConnectionStatus status);
    
    /**
     * Find active social accounts by user
     */
    List<SocialAccount> findActiveAccountsByUserId(UserId userId);
    
    /**
     * Find active social accounts by company
     */
    List<SocialAccount> findActiveAccountsByCompanyId(CompanyId companyId);
    
    /**
     * Check if user has account on specific social network
     */
    boolean existsByUserIdAndSocialNetworkId(UserId userId, SocialNetworkId socialNetworkId);
    
    /**
     * Check if platform account already exists
     */
    boolean existsByPlatformAccountIdAndSocialNetworkId(String platformAccountId, SocialNetworkId socialNetworkId);
    
    /**
     * Delete social account (hard delete - use with caution)
     */
    void delete(SocialAccountId id);
    
    /**
     * Get total count of social accounts
     */
    long countSocialAccounts();
    
    /**
     * Get count of active social accounts
     */
    long countActiveSocialAccounts();
    
    /**
     * Get count by company
     */
    long countByCompanyId(CompanyId companyId);
    
    /**
     * Get count by user
     */
    long countByUserId(UserId userId);
}
