from flask import Blueprint, request
from dependency_injector.wiring import inject, Provide
from app.di_container import Container
from app.controllers import SubjectController


subject_blueprint = Blueprint("subject", __name__)


@subject_blueprint.route("", methods=["POST"])
@inject
def create_subject(
    controller: SubjectController = Provide[Container.subject_controller],
):
    return controller.create(request.get_json())


@subject_blueprint.route("", methods=["GET"])
@inject
def get_all_subjects(
    controller: SubjectController = Provide[Container.subject_controller],
):
    return controller.get_all()


@subject_blueprint.route("/<subject_id>", methods=["GET"])
@inject
def get_subject(
    subject_id: str,
    controller: SubjectController = Provide[Container.subject_controller],
):
    return controller.get_by_id(subject_id)


@subject_blueprint.route("/<subject_id>", methods=["PUT"])
@inject
def update_subject(
    subject_id: str,
    controller: SubjectController = Provide[Container.subject_controller],
):
    return controller.update(subject_id, request.get_json())


@subject_blueprint.route("/<subject_id>", methods=["DELETE"])
@inject
def delete_subject(
    subject_id: str,
    controller: SubjectController = Provide[Container.subject_controller],
):
    return controller.delete(subject_id)
