"""
Base class for all GCP service emulators.

Each service registers Flask blueprints with route handlers that
mimic the real GCP REST API.
"""

from abc import ABC, abstractmethod
from typing import Optional

from flask import Blueprint

from gcplocal.state import StateStore, state as global_state


class GCPService(ABC):
    """Abstract base for a GCP service emulator."""

    def __init__(self, state: Optional[StateStore] = None):
        self.state = state or global_state

    @property
    @abstractmethod
    def service_name(self) -> str:
        """Short name of the service, e.g. 'compute'."""

    @property
    @abstractmethod
    def api_prefix(self) -> str:
        """URL prefix this service handles, e.g. '/compute/v1'."""

    @abstractmethod
    def register_routes(self, blueprint: Blueprint) -> None:
        """Register all route handlers on the given blueprint."""

    def create_blueprint(self) -> Blueprint:
        bp = Blueprint(self.service_name, __name__)
        self.register_routes(bp)
        return bp
