from flask import Blueprint, jsonify
from flask_restplus import Api

from willstores.controller import (
    startAPI, 
    productAPI, 
    genderAPI, 
    sessionAPI,
    queryAPI,
    brandAPI,
    kindAPI
)

bpapi = Blueprint("api", __name__)

api = Api(bpapi, title="WillStores API", description="API of WillStores web service.")

api.add_namespace(startAPI, path="/start")
api.add_namespace(productAPI, path="/product")
api.add_namespace(genderAPI, path="/gender")
api.add_namespace(sessionAPI, path="/session")

api.add_namespace(queryAPI, path="/search/query")
api.add_namespace(brandAPI, path="/search/brand")
api.add_namespace(kindAPI, path="/search/kind")

@bpapi.app_errorhandler(404)
def not_found(e):
    error = {
        "error": "Not found - @WillStores"
    }
    return jsonify(error), 404

@bpapi.app_errorhandler(405)
def method_not_allowed(e):
    error = {
        "error": "Method not allowed - @WillStores"
    }
    return jsonify(error), 405