"Fast API module for the recommender system"
from fastapi import APIRouter

from services.recommender.acquisitions_recommender import \
    AcquisitionsRecommender
from services.recommender.pe_recommendation import PERecommendation
# from the parent directory
from utils import url_parser

recommendation = APIRouter(
    prefix="/recommender",
    tags=["recommender"],
    responses={404: {"description": "Not found"}},
    dependencies=[],  # add dependencies here
)


# get company url from the url path and acq_direction from the query parameter
@recommendation.post("/recommendations/")
async def get_recommendations(
    company_url: str, acq_direction: str = None, public: bool = None
):
    "Get recommendations for a company"
    company_url_parsed = url_parser.parsed_url(company_url)
    rec = AcquisitionsRecommender()
    recommender_output = rec.get_recommendations(
        company_url_parsed.url, acq_direction, public
    )
    return rec.transform_recommender_output_for_front_end(recommender_output)


@recommendation.post("/recommendations/funds/")
async def get_fund_recommendations(company_url: str):
    "Get recommendations for a company"
    company_url_parsed = url_parser.parsed_url(company_url)
    rec = PERecommendation()
    recommender_output = rec.get_recommendations(company_url_parsed.url)
    return rec.transform_recommender_output_for_front_end(recommender_output)


@recommendation.post("/public_comps/")
async def get_public_comps(company_url: str):
    "Get public companies for a company"
    company_url_parsed = url_parser.parsed_url(company_url)
    rec = AcquisitionsRecommender()
    recommender_output = rec.get_public_comps(company_url_parsed.url)
    return rec.transform_recommender_output_for_front_end(recommender_output)


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(recommendation)
