from flask import request, jsonify
from flask.views import MethodView
from app.services.session_service import SessionService
from app.helpers import make_response


class SessionController(MethodView):
    def __init__(self, session_service: SessionService):
        self.session_service = session_service

    def createRoom(self, data):

        required_fields = [
            "quiz_id",
            "host_id",
            "limit_participan",
        ]
        for field in required_fields:
            if field not in data:
                return jsonify({"error": f"Missing field: {field}"}), 400

        session = self.session_service.create_session(
            quiz_id=data["quiz_id"],
            host_id=data["host_id"],
            limit_participan=data["limit_participan"],
        )

        return make_response(
            message="succes create room",
            data=session,
            status_code=201,
        )
