from fastapi import APIRouter
from app.models.explore_models import ExploreConfigResponse, ExploreConfigData, ExploreCategoryResponse, ExploreSourceResponse

router = APIRouter()

# Default Explore Categories
EXPLORE_CATEGORIES = [
    ExploreCategoryResponse(id="all", label="All"),
    ExploreCategoryResponse(id="free", label="Free"),
    ExploreCategoryResponse(id="paid", label="Paid"),
    ExploreCategoryResponse(id="verified", label="World"),
]

# Default Explore Sources
EXPLORE_SOURCES = [
    ExploreSourceResponse(
        baseUrl="https://masa49.org/",
        nickname="Masa",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/logo%20(1).png",
        accentColor="#7C4DFF",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://masa49.org/?s={query}",
        sourceId="masa",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://xhamster.com/",
        nickname="xHamster",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon.ico",
        accentColor="#FF5252",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://xhamster.com/search/{query}",
        sourceId="xhamster",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://www.xnxx.com/",
        nickname="XNXX",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(1).ico",
        accentColor="#448AFF",
        category="free",
        isVerified=True,
        hasCategories=True,
        searchUrlTemplate="https://www.xnxx.com/search/{query}",
        sourceId="xnxx",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://www.xvideos.com/",
        nickname="XVideos",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(2).ico",
        accentColor="#FFAB40",
        category="free",
        isVerified=True,
        hasCategories=True,
        searchUrlTemplate="https://www.xvideos.com/?k={query}",
        sourceId="xvideos",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://www.pornhub.com/",
        nickname="Pornhub",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(3).ico",
        accentColor="#FF9100",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://www.pornhub.com/video/search?search={query}",
        sourceId="pornhub",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://www.youporn.com/",
        nickname="YouPorn",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(4).ico",
        accentColor="#FF4081",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://www.youporn.com/search/?query={query}",
        sourceId="youporn",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://www.redtube.com/",
        nickname="RedTube",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(5).ico",
        accentColor="#D32F2F",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://www.redtube.com/?search={query}",
        sourceId="redtube",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://beeg.com/",
        nickname="Beeg",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/logo%20(2).png",
        accentColor="#00BFA5",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://beeg.com/?f={query}",
        sourceId="beeg",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://spankbang.com/",
        nickname="SpankBang",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(6).ico",
        accentColor="#FFC107",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://spankbang.com/s/{query}/",
        sourceId="spankbang",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://fapnut.net/",
        nickname="OnlyFans",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(7).ico",
        accentColor="#00AFF0",
        category="paid",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://fapnut.net/?s={query}",
        sourceId="fapnut",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://pornxp.io/",
        nickname="PornXP",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon.png",
        accentColor="#1a2137",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://pornxp.io/search?q={query}",
        sourceId="pornxp",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://hqporner.com/",
        nickname="HQPorner",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(8).ico",
        accentColor="#E91E63",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://hqporner.com/?q={query}",
        sourceId="hqporner",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://xxxparodyhd.net/",
        nickname="XXXParodyHD",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/xxx.png",
        accentColor="#E040FB",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://xxxparodyhd.net/?s={query}",
        sourceId="xxxparodyhd",
        disable=False,
    ),
    ExploreSourceResponse(
        baseUrl="https://www.pornwex.tv/",
        nickname="PornWex",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(18).ico",
        accentColor="#FF6D00",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://www.pornwex.tv/search/{query}/",
        sourceId="pornwex",
        disable=True,
    ),
    ExploreSourceResponse(
        baseUrl="https://www.tube8.com/",
        nickname="Tube8",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(17).ico",
        accentColor="#E53935",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://www.tube8.com/searches.html/?q={query}",
        sourceId="tube8",
        disable=False,
        pageSize=54,
    ),
    ExploreSourceResponse(
        baseUrl="https://www.pornhat.com/",
        nickname="PornHat",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(16).ico",
        accentColor="#212121",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://www.pornhat.com/search/{query}/",
        sourceId="pornhat",
        disable=False,
        pageSize=60,
    ),
    ExploreSourceResponse(
        baseUrl="https://brazzpw.com/",
        nickname="BrazzPW",
        favicon="https://github.com/milon4999/apphub-release/raw/refs/heads/main/logo/favicon%20(15).ico",
        accentColor="#FF9800",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://brazzpw.com/search/free-brazz-premium-full-new-jan-2026/?s={query}",
        sourceId="brazzpw",
        disable=False,
        pageSize=100,
    ),
    ExploreSourceResponse(
        baseUrl="https://www.gosexpod.com/",
        nickname="Gosexpod",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(14).ico",
        accentColor="#673AB7",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://www.gosexpod.com/search/videos?q={query}",
        sourceId="gosexpod",
        disable=False,
        pageSize=48,
    ),
    ExploreSourceResponse(
        baseUrl="https://watcherotic.com/",
        nickname="Watcherotic",
        favicon="https://raw.githubusercontent.com/milon4999/apphub-release/refs/heads/main/logo/favicon%20(13).ico",
        accentColor="#00BCD4",
        category="free",
        isVerified=False,
        hasCategories=True,
        searchUrlTemplate="https://watcherotic.com/search/{query}/",
        sourceId="watcherotic",
        disable=False,
        pageSize=100,
    ),
]

EXPLORE_CONFIG = ExploreConfigData(
    title="SOURCES",
    categories=EXPLORE_CATEGORIES,
    sources=EXPLORE_SOURCES
)

@router.get("/explore/config", response_model=ExploreConfigResponse, tags=["Explore"])
async def get_explore_config() -> ExploreConfigResponse:
    """
    Get the configuration for the Explore Page, including available categories and sources.
    This allows the Explore page to be fully backend-driven.
    """
    # Filter sources to only include those not disabled
    enabled_sources = [source for source in EXPLORE_SOURCES if not source.disable]
    
    # Create a copy of the config with only enabled sources
    filtered_config = ExploreConfigData(
        title=EXPLORE_CONFIG.title,
        categories=EXPLORE_CONFIG.categories,
        sources=enabled_sources
    )
    
    return ExploreConfigResponse(
        status="success",
        data=filtered_config
    )
