from flask import Flask,jsonify
from flask_restful import Resource, Api
import json
from backend.services.mongo_service import MongoService
from bson import json_util

app = Flask(__name__)
api = Api(app)


class MovieApi(Resource):
    mongoService: MongoService

    def __init__(self):
        self.mongoService = MongoService()

    def get(self):
        # response_array = list(self.mongoService.getAllMovies())
        response_array = []
        for movie in self.mongoService.getAllMovies():
            if '_id' in movie: del movie['_id']
            response_array.append(movie)
            # break
        # json_sent = json.dumps(response_array, default=json_util.default)
        # json_sent = json.dumps(response_array, indent=4, sort_keys=True, default=str)
        return jsonify(response_array)
        # return dumps(self.mongoService.getAllMovies(), json_options=DEFAULT_JSON_OPTIONS)

class CinemaApi(Resource):
    mongoService: MongoService

    def __init__(self):
        self.mongoService = MongoService()

    def get(self):
        # response_array = list(self.mongoService.getAllMovies())
        response_array = []
        for cinema in self.mongoService.getAllCinemaScreenings():
            if '_id' in cinema: del cinema['_id']
            response_array.append(cinema)
            # break
        # json_sent = json.dumps(response_array, default=json_util.default)
        # json_sent = json.dumps(response_array, indent=4, sort_keys=True, default=str)
        return jsonify(response_array)
        # return dumps(self.mongoService.getAllMovies(), json_options=DEFAULT_JSON_OPTIONS)


api.add_resource(MovieApi, '/movie')
api.add_resource(CinemaApi, '/cinema')

if __name__ == '__main__':
    app.run(debug=True)
