##############################################################################
# ScoDoc
# Copyright (c) 1999 - 2023 Emmanuel Viennet.  All rights reserved.
# See LICENSE
##############################################################################

"""
  ScoDoc 9 API : jury   WIP
"""

from flask import jsonify
from flask_login import login_required

import app
from app.api import api_bp as bp, api_web_bp
from app.decorators import scodoc, permission_required
from app.scodoc.sco_exceptions import ScoException
from app.but import jury_but_results
from app.models import FormSemestre
from app.scodoc.sco_permissions import Permission


@bp.route("/formsemestre/<int:formsemestre_id>/decisions_jury")
@api_web_bp.route("/formsemestre/<int:formsemestre_id>/decisions_jury")
@login_required
@scodoc
@permission_required(Permission.ScoView)
def decisions_jury(formsemestre_id: int):
    """Décisions du jury des étudiants du formsemestre."""
    # APC, pair:
    formsemestre: FormSemestre = FormSemestre.query.get(formsemestre_id)
    if formsemestre.formation.is_apc():
        app.set_sco_dept(formsemestre.departement.acronym)
        rows = jury_but_results.get_jury_but_results(formsemestre)
        return jsonify(rows)
    else:
        raise ScoException("non implemente")