"""
Constants and Configuration for Influencers App

This module centralizes all constants, error messages, and configuration values
used throughout the influencers app for better maintainability.
"""

# ============================================================================
# INSTAGRAM API CONFIGURATION
# ============================================================================

# Instagram Graph API version
INSTAGRAM_API_VERSION = "v24.0"

# Base URLs for Instagram Graph API
INSTAGRAM_GRAPH_API_BASE_URL = f"https://graph.facebook.com/{INSTAGRAM_API_VERSION}"
FACEBOOK_OAUTH_BASE_URL = f"https://www.facebook.com/{INSTAGRAM_API_VERSION}/dialog/oauth"

# Data fetching limits
MAX_MEDIA_POSTS_TO_FETCH = 100  # Maximum number of posts to fetch per influencer
MIN_FOLLOWERS_FOR_DEMOGRAPHICS = 100  # Minimum followers needed for real demographic data


# ============================================================================
# DATA PROCESSING STATUS
# ============================================================================

class ProcessingStatus:
    """Data processing status constants"""
    PENDING = 'PENDING'
    PROCESSING = 'PROCESSING'
    COMPLETED = 'COMPLETED'
    FAILED = 'FAILED'


# ============================================================================
# MEDIA TYPES
# ============================================================================

class MediaType:
    """Instagram media types"""
    IMAGE = 'IMAGE'
    VIDEO = 'VIDEO'
    CAROUSEL_ALBUM = 'CAROUSEL_ALBUM'


# ============================================================================
# INSIGHT METRICS
# ============================================================================

# Account-level insights metrics
ACCOUNT_INSIGHTS_METRICS = {
    'profile_views': {
        'period': 'day',
        'metric_type': 'total_value',
        'description': 'Total profile views in the last 30 days'
    },
    'follower_count': {
        'period': 'day',
        'description': 'Daily follower count for growth calculation'
    },
}

# Media-level insights metrics
MEDIA_INSIGHTS_IMAGE = ['impressions', 'reach', 'engagement', 'saved']
MEDIA_INSIGHTS_VIDEO = ['impressions', 'reach', 'engagement', 'saved', 'video_views']

# Demographics metrics
DEMOGRAPHICS_METRICS = {
    'follower_demographics': {
        'period': 'lifetime',
        'metric_type': 'total_value',
        'breakdowns': 'age,gender'
    },
    'reached_audience_demographics': {
        'period': 'lifetime',
        'metric_type': 'total_value',
        'timeframe': 'this_month',
        'breakdowns': 'age'
    },
    'engaged_audience_demographics': {
        'period': 'lifetime',
        'metric_type': 'total_value',
        'timeframe': 'this_month',
        'breakdowns': 'age'
    }
}


# ============================================================================
# NICHE PREDICTION
# ============================================================================

# Keyword-based niche classification (placeholder for ML model)
NICHE_KEYWORDS = {
    'fashion': ['fashion', 'style', 'ootd', 'outfit', 'clothing', 'designer'],
    'fitness': ['fitness', 'workout', 'gym', 'exercise', 'training', 'muscle'],
    'food': ['food', 'recipe', 'cooking', 'chef', 'delicious', 'meal'],
    'travel': ['travel', 'vacation', 'trip', 'adventure', 'explore', 'destination'],
    'beauty': ['beauty', 'makeup', 'cosmetics', 'skincare', 'lipstick'],
    'tech': ['tech', 'technology', 'software', 'coding', 'programming', 'gadget'],
}

DEFAULT_NICHE = 'lifestyle'


# ============================================================================
# ML MODEL CLASSES (Imported from core.constants)
# ============================================================================

# Import shared constants from core to maintain single source of truth
from core.constants import NICHE_CLASSES, POPULARITY_CLASSES, POPULARITY_TIERS


# ============================================================================
# ERROR MESSAGES
# ============================================================================

class ErrorMessages:
    """Centralized error messages for consistent user feedback"""

    # Authentication errors
    NOT_INFLUENCER = 'Only influencers can connect Instagram accounts. Please register as an influencer to continue.'
    NOT_BUSINESS = 'Only businesses can access this feature. Please register as a business to continue.'

    # OAuth errors
    NO_AUTH_CODE = 'Authorization was not completed. Please try connecting your Instagram account again.'
    NO_STATE_PARAM = 'Connection session expired. Please try connecting your Instagram account again.'
    INVALID_STATE = 'Connection session is invalid. Please try connecting your Instagram account again.'
    STATE_DECODE_FAILED = 'Connection session could not be verified. Please try again.'
    USER_NOT_FOUND = 'Your account could not be found. Please log in and try again.'
    USER_LOOKUP_FAILED = 'Unable to verify your account. Please log in and try again.'

    # Token errors
    TOKEN_EXCHANGE_FAILED = 'Instagram authorization failed. Please try connecting your account again.'
    LONG_TOKEN_FAILED = 'Could not complete Instagram connection. Please try again.'
    TOKEN_ENCRYPTION_FAILED = 'Security error during connection. Please contact support.'
    NO_ACCESS_TOKEN = 'Instagram connection expired. Please reconnect your account.'

    # Instagram account errors - User-friendly messages
    PAGES_FETCH_FAILED = 'Could not access your Facebook Pages. Please ensure your Instagram account is linked to a Facebook Page.'
    NO_FACEBOOK_PAGES = (
        'No Facebook Page found linked to your account. '
        'To connect your Instagram, you need to: '
        '1) Convert your Instagram to a Business or Creator account, '
        '2) Create or link a Facebook Page, '
        '3) Connect your Instagram to that Facebook Page in Instagram settings.'
    )
    IG_ACCOUNT_LOOKUP_FAILED = 'Could not find your Instagram Business Account. Please ensure your Instagram is converted to a Business or Creator account.'
    NO_INSTAGRAM_ACCOUNT = (
        'No Instagram Business Account found. '
        'Your Instagram must be a Business or Creator account (not Personal) '
        'and must be connected to a Facebook Page. '
        'Please convert your account in Instagram settings and try again.'
    )
    EMPTY_INSTAGRAM_HANDLE = 'Could not retrieve your Instagram username. Please try again.'
    HANDLE_ALREADY_CONNECTED = 'This Instagram account is already connected to another SYNC user. Each Instagram account can only be connected to one SYNC account.'

    # Profile errors
    PROFILE_SAVE_FAILED = 'Could not save your profile. Please try again or contact support.'
    PROFILE_NOT_FOUND = 'Profile not found. Please connect your Instagram account first.'

    # Data processing errors
    DATA_ALREADY_PROCESSING = 'Your data is already being processed. Please wait for it to complete.'
    REFRESH_OWN_DATA_ONLY = 'You can only refresh your own data.'
    NO_INSTAGRAM_BUSINESS_ID = 'Your Instagram Business Account ID is missing. Please reconnect your account.'


# ============================================================================
# SUCCESS MESSAGES
# ============================================================================

class SuccessMessages:
    """Centralized success messages"""
    
    REGISTRATION_SUCCESS = 'User registered successfully'
    PASSWORD_CHANGED = 'Password changed successfully'
    INSTAGRAM_CONNECTED = 'Instagram account connected. Data processing started.'
    DATA_REFRESH_STARTED = 'Data refresh started'
    DATA_PROCESSING_COMPLETE = 'Data processing completed successfully'

