import os

from .base import PMSConnector
from .errors import PMSConfigurationRequired


REQUIRED_ENV = [
    "OPERA_BASE_URL",
    "OPERA_CLIENT_ID",
    "OPERA_CLIENT_SECRET",
    "OPERA_APP_KEY",
    "OPERA_ENTERPRISE_ID",
    "OPERA_PROPERTY_ID",
]


class OracleOperaCloudConnector(PMSConnector):
    provider = "opera_cloud"

    def __init__(self, config):
        super().__init__(config)
        self.env = {key: os.environ.get(key, "") for key in REQUIRED_ENV}

    def validate_environment(self):
        missing = [key for key, value in self.env.items() if not value]
        if missing:
            raise PMSConfigurationRequired(
                "Missing OPERA environment variables: " + ", ".join(missing)
            )
        if not self.config.get("property_id"):
            raise PMSConfigurationRequired("Missing hotel PMS property ID")

    def _official_ohip_placeholder(self, operation):
        self.validate_environment()
        raise PMSConfigurationRequired(
            f"{operation} requires official Oracle OHIP API documentation, "
            "hotel credentials, application key, property ID, and granted API permissions. "
            "No Oracle endpoint URL is hardcoded in this demo layer."
        )

    def getGuestByRoom(self, room_id):
        return self._official_ohip_placeholder("getGuestByRoom")

    def getReservation(self, room_id):
        return self._official_ohip_placeholder("getReservation")

    def verifyGuest(self, room_id, secure_room_id=None):
        return self._official_ohip_placeholder("verifyGuest")

    def getCheckedInGuests(self):
        return self._official_ohip_placeholder("getCheckedInGuests")

    def getRoomStatus(self, room_id):
        return self._official_ohip_placeholder("getRoomStatus")

    def postChargeToRoom(self, charge):
        return self._official_ohip_placeholder("postChargeToRoom")

    def getCheckInStatus(self, room_id):
        return self._official_ohip_placeholder("getCheckInStatus")

    def getCheckOutStatus(self, room_id):
        return self._official_ohip_placeholder("getCheckOutStatus")
