from flask import Blueprint, abort, jsonify

from src.lib.artist import approve_unapproved_link_request, reject_unapproved_link_request
from src.utils.decorators import require_login
from src.types.account.account import Account


bp = Blueprint("creator_link_requests", __name__)


@bp.post("/creator_link_requests/<int:request_id>/approve")
@require_login
def approve_request(request_id: int, user: Account):
    if user.role not in ["moderator", "administrator"]:
        return abort(404)
    approve_unapproved_link_request(request_id)
    return jsonify({"response": "approved"})


@bp.post("/creator_link_requests/<int:request_id>/reject")
@require_login
def reject_request(request_id: int, user: Account):
    if user.role not in ["moderator", "administrator"]:
        return abort(404)
    reject_unapproved_link_request(request_id)
    return jsonify({"response": "rejected"})
