from flask import Blueprint
from app.service import SampleService
from app.schemas import UserResponseSchema

sample_router = Blueprint('main', __name__)


@sample_router.route('/', methods=['GET'])
def index():
   function_name = "Ping Private Route- Health Check"
    logger.info(
        message=f"Enter - {function_name}",
        function_name=function_name,
    )
    return Response({"message": "Hello World", "status": "Ok"},
                    status=200,
                    mimetype='application/json',
                    )


@sample_router.route('/get-all-users', methods=['GET'])
def get_all_users():
    function_name = "Get All Users - Controller"
    logger.info(
        message=f"Enter - {function_name}",
        function_name=function_name,
    )
    try:
        users: list[UserSchema] = SampleService().get_all_users()
        logger.info(
            message=f"Exit - {function_name}",
            function_name=function_name,
        )
        return Response({"message": "Success", "status": "Ok", "data": users},
                        status=200,
                        mimetype='application/json',
                        )
    except Exception as exception:
        logger.error(
            message=f"Exit - {function_name} - Exception Occurred: {exception}",
            function_name=function_name,
        )
        return Response({"message": "Error", "status": "Not Ok", "error": str(exception)},
                        status=500,
                        mimetype='application/json',
                        )
