from fastapi import APIRouter, Depends

from events.pages.events import PageHandlers
from index import endpoints_index

from validations.request.restrictions.validations import RequestApplication
from api_validations.defaults.validations import CommonHeaders


pages_route = APIRouter(prefix="/restrictions", tags=["Restrictions Cluster"])


application_retrieve_page = "ApplicationRetrievePage"
@pages_route.post(
    path="/page/valid",
    summary="Verify if page is valid returns application available",
    description="Verify if page is valid returns application available",
    operation_id=endpoints_index[application_retrieve_page]
)
def authentication_page_valid(data: RequestApplication, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
    """
    Verify if page is valid returns application that can user reach
    page: { url = /building/create} | result: { "application": "4c11f5ef-0bbd-41ac-925e-f79d9aac2b0e" }
    """
    list_of = PageHandlers.retrieve_valid_page_via_token(access_token=headers.token, page_url=data.page)
    print('list_of', list_of)
    return {"completed": True, "application": list_of}


application_retrieve_all_sites = "ApplicationRetrieveAllSites"
@pages_route.get(
    path="/sites/list",
    summary="Lists all sites that are available for user",
    description="Lists all sites that are available for user",
    operation_id=endpoints_index[application_retrieve_all_sites]
)
def authentication_get_all_sites_list(headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
    """
    Verify if page is valid returns application that can user reach result: { "sites": ['/dashboard', '/building/create'] }
    """
    list_of_application_url = PageHandlers.retrieve_valid_sites_via_token(access_token=headers.token)
    print('list_of_application_url', list(list_of_application_url))
    return {"completed": True, "sites": list(list_of_application_url)}
