from flask_pymongo.wrappers import Database
from pymongo import MongoClient


class MongoService:
    client: MongoClient
    db: Database

    def __init__(self):
        self.client = MongoClient('mongodb://localhost:27017/')
        self.db = self.client['filmDb']

    def saveFilmList(self, list):
        collection = self.db['movie']
        collection.insert(list)

    def saveCinemaInfo(self, dict):
        # db = self.client['filmDb']
        collection = self.db['screenings']
        collection.insert(dict)

    def saveVenue(self, save_dict):
        collection = self.db['cinema']
        collection.insert(save_dict)

    def dropCollection(self, collection):
        collection = self.db[collection]
        collection.drop()

    def getCinemasByCompanyName(self, name):
        # db = self.client['filmDb']
        collection = self.db['cinema_venues']
        return collection.find({'company': name})

    def getAllCinemaVenues(self):
        collection = self.db['cinema_venues']
        return collection.find()

    def getAllCinemaScreenings(self):
        collection = self.db['cinema']
        return collection.find()

    def getAllScreenings(self):
        collection = self.db['screenings']
        return collection.find()

    def getAllMovies(self):
        collection = self.db['movie']
        return collection.find()
