"""Default cover/avatar URLs for profiles imported without legacy media."""

SEEKER_COVER_POOL = [
    'https://images.unsplash.com/photo-1497366216548-37526070297c?w=600&q=70',
    'https://images.unsplash.com/photo-1461749280684-dccba630e2f6?w=600&q=70',
    'https://images.unsplash.com/photo-1542744173-8e7e53415bb0?w=600&q=70',
    'https://images.unsplash.com/photo-1503387762-592deb58ef4e?w=600&q=70',
    'https://images.unsplash.com/photo-1551288049-bebda4e38f71?w=600&q=70',
    'https://images.unsplash.com/photo-1521737711867-e3b97375f902?w=600&q=70',
    'https://images.unsplash.com/photo-1522071820081-009f0129c71c?w=600&q=70',
    'https://images.unsplash.com/photo-1600880292203-757bb62b4baf?w=600&q=70',
]

SEEKER_AVATAR_POOL = [
    'https://images.unsplash.com/photo-1573496359142-b8d87734a5a2?w=150&q=75&fit=crop&crop=face',
    'https://images.unsplash.com/photo-1556157382-97eda2f9aa60?w=150&q=75&fit=crop&crop=face',
    'https://images.unsplash.com/photo-1508214751196-bcfd4ca60f91?w=150&q=75&fit=crop&crop=face',
    'https://images.unsplash.com/photo-1519085360753-af0119f7cbe7?w=150&q=75&fit=crop&crop=face',
    'https://images.unsplash.com/photo-1580489944761-15a19d654956?w=150&q=75&fit=crop&crop=face',
    'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=150&q=75&fit=crop&crop=face',
    'https://images.unsplash.com/photo-1560250097-0b93528c311a?w=150&q=75&fit=crop&crop=face',
    'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&q=75&fit=crop&crop=face',
]

COMPANY_COVER_POOL = [
    'https://images.unsplash.com/photo-1497366216548-37526070297c?w=600&q=60',
    'https://images.unsplash.com/photo-1486325212027-8081e485255e?w=600&q=60',
    'https://images.unsplash.com/photo-1504307651254-35680f356dfd?w=600&q=60',
    'https://images.unsplash.com/photo-1541354329998-f4d9a9f9297f?w=600&q=60',
    'https://images.unsplash.com/photo-1560179707-f14e90ef3623?w=600&q=60',
    'https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=600&q=60',
    'https://images.unsplash.com/photo-1444653614773-995cb1ef9efa?w=600&q=60',
    'https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?w=600&q=60',
]

INDUSTRY_COVERS = {
    'telecommunications': 'https://images.unsplash.com/photo-1497366216548-37526070297c?w=600&q=60',
    'energy-utilities': 'https://images.unsplash.com/photo-1504307651254-35680f356dfd?w=600&q=60',
    'banking-finance': 'https://images.unsplash.com/photo-1541354329998-f4d9a9f9297f?w=600&q=60',
    'technology': 'https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=600&q=60',
    'retail': 'https://images.unsplash.com/photo-1444653614773-995cb1ef9efa?w=600&q=60',
    'fmcg-manufacturing': 'https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?w=600&q=60',
    'healthcare': 'https://images.unsplash.com/photo-1519494026892-80bbd2d6fd0d?w=600&q=60',
    'education': 'https://images.unsplash.com/photo-1523050854058-8df90110c9f1?w=600&q=60',
    'construction': 'https://images.unsplash.com/photo-1503387762-592deb58ef4e?w=600&q=60',
    'mining': 'https://images.unsplash.com/photo-1581094794329-c8112a89af12?w=600&q=60',
    'agriculture': 'https://images.unsplash.com/photo-1625246333195-78d9c38ad449?w=600&q=60',
    'hospitality': 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=600&q=60',
}

CATEGORY_COVERS = {
    'finance-accounting': 'https://images.unsplash.com/photo-1551288049-bebda4e38f71?w=600&q=70',
    'engineering': 'https://images.unsplash.com/photo-1503387762-592deb58ef4e?w=600&q=70',
    'information-technology': 'https://images.unsplash.com/photo-1461749280684-dccba630e2f6?w=600&q=70',
    'healthcare': 'https://images.unsplash.com/photo-1576091160399-112ba8d25d1d?w=600&q=70',
    'marketing': 'https://images.unsplash.com/photo-1542744173-8e7e53415bb0?w=600&q=70',
    'human-resources': 'https://images.unsplash.com/photo-1521737711867-e3b97375f902?w=600&q=70',
    'legal': 'https://images.unsplash.com/photo-1589829545856-d10d557cf95f?w=600&q=70',
    'education': 'https://images.unsplash.com/photo-1523050854058-8df90110c9f1?w=600&q=70',
}

LEGACY_SKIP_IMAGES = {
    '',
    'cover.png',
    'default.png',
    'company_default.png',
}

DEMO_IMAGE_HOSTS = ('images.unsplash.com', 'unsplash.com', 'source.unsplash.com')


def is_demo_image_url(url):
    """True for stock/demo URLs (Unsplash etc.), not user-uploaded media."""
    if not url:
        return False
    normalized = str(url).strip().lower()
    return any(host in normalized for host in DEMO_IMAGE_HOSTS)


def _pick_from_pool(seed, pool):
    return pool[hash(seed) % len(pool)]


def default_company_cover(company):
    slug = (company.industry_slug or '').strip()
    if slug in INDUSTRY_COVERS:
        return INDUSTRY_COVERS[slug]
    return _pick_from_pool(company.slug or str(company.pk), COMPANY_COVER_POOL)


def default_seeker_cover(seeker):
    slug = (seeker.category_slug or '').strip()
    if slug in CATEGORY_COVERS:
        return CATEGORY_COVERS[slug]
    return _pick_from_pool(seeker.slug or str(seeker.pk), SEEKER_COVER_POOL)


def default_seeker_avatar(seeker):
    return _pick_from_pool(f'avatar-{seeker.slug or seeker.pk}', SEEKER_AVATAR_POOL)


def legacy_media_url(path, media_url='/media/'):
    """Turn a legacy ImageField path into a URL (when the file exists under MEDIA_ROOT)."""
    if not path:
        return ''
    path = str(path).strip().replace('\\', '/')
    if path in LEGACY_SKIP_IMAGES:
        return ''
    if path.startswith(('http://', 'https://', '/')):
        return path
    return f'{media_url.rstrip("/")}/{path.lstrip("/")}'
