from flask import jsonify, make_response

from src.lib.post import get_post_comments
from src.lib.api import create_not_found_error_response
from src.pages.api.v1 import v1api_bp


@v1api_bp.get("/<service>/user/<creator_id>/post/<post_id>/comments")
def get_comments(service: str, creator_id: str, post_id: str):
    comments = get_post_comments(post_id, service)

    if not comments:
        response = create_not_found_error_response("No comments found.")
        response.headers["Cache-Control"] = "s-maxage=600"

        return response

    response = make_response(jsonify(comments), 200)
    response.headers["Cache-Control"] = "s-maxage=600"

    return response
