# Path: custom_components/frigate/const.py
# ATTR_CLIENT_ID = "client_id"
# 
# ATTR_CONFIG = "config"
# 
# ATTR_MQTT = "mqtt"
# 
# CONF_NOTIFICATION_PROXY_ENABLE = "notification_proxy_enable"
# 
# DOMAIN = "frigate"


import asyncio
import logging
import aiohttp
import jwt
from http import HTTPStatus
from ipaddress import ip_address
from typing import Any, Optional, cast
from aiohttp import hdrs, web
from aiohttp.web_exceptions import HTTPBadGateway, HTTPUnauthorized
from multidict import CIMultiDict
from yarl import URL
from custom_components.frigate.const import (
    ATTR_CLIENT_ID,
    ATTR_CONFIG,
    ATTR_MQTT,
    CONF_NOTIFICATION_PROXY_ENABLE,
    DOMAIN,
)
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http.auth import DATA_SIGN_SECRET, SIGN_QUERY_PARAM
from homeassistant.components.http.const import KEY_HASS
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_URL
from homeassistant.core import HomeAssistant

    def _create_path(self, **kwargs: Any) -> str | None:
        """Create path."""
        return f"api/events/{kwargs['eventid']}/snapshot.jpg"


class NotificationsProxyView(ProxyView):
    """A proxy for notifications."""

    url = "/api/frigate/{frigate_instance_id:.+}/notifications/{event_id}/{path:.*}"
    extra_urls = ["/api/frigate/notifications/{event_id}/{path:.*}"]

    name = "api:frigate:notification"
    requires_auth = False

    def _create_path(self, **kwargs: Any) -> str | None:
        """Create path."""
        path, event_id = kwargs["path"], kwargs["event_id"]
        if path == "thumbnail.jpg":
            return f"api/events/{event_id}/thumbnail.jpg"

        if path == "snapshot.jpg":
            return f"api/events/{event_id}/snapshot.jpg"

        if path.endswith("clip.mp4"):
            return f"api/events/{event_id}/clip.mp4"
        return None

    def _permit_request(self, request: web.Request, config_entry: ConfigEntry) -> bool:
        """Determine whether to permit a request."""

# Path: custom_components/frigate/const.py
# ATTR_CLIENT_ID = "client_id"
# 
# ATTR_CONFIG = "config"
# 
# ATTR_MQTT = "mqtt"
# 
# CONF_NOTIFICATION_PROXY_ENABLE = "notification_proxy_enable"
# 
# DOMAIN = "frigate"


# Path: custom_components/frigate/views.py
import asyncio
import logging
import aiohttp
import jwt
from http import HTTPStatus
from ipaddress import ip_address
from typing import Any, Optional, cast
from aiohttp import hdrs, web
from aiohttp.web_exceptions import HTTPBadGateway, HTTPUnauthorized
from multidict import CIMultiDict
from yarl import URL
from custom_components.frigate.const import (
    ATTR_CLIENT_ID,
    ATTR_CONFIG,
    ATTR_MQTT,
    CONF_NOTIFICATION_PROXY_ENABLE,
    DOMAIN,
)
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http.auth import DATA_SIGN_SECRET, SIGN_QUERY_PARAM
from homeassistant.components.http.const import KEY_HASS
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_URL
from homeassistant.core import HomeAssistant


    def _create_path(self, **kwargs: Any) -> str | None:
        """Create path."""
        return f"api/events/{kwargs['eventid']}/snapshot.jpg"


class NotificationsProxyView(ProxyView):
    """A proxy for notifications."""

    url = "/api/frigate/{frigate_instance_id:.+}/notifications/{event_id}/{path:.*}"
    extra_urls = ["/api/frigate/notifications/{event_id}/{path:.*}"]

    name = "api:frigate:notification"
    requires_auth = False

    def _create_path(self, **kwargs: Any) -> str | None:
        """Create path."""
        path, event_id = kwargs["path"], kwargs["event_id"]
        if path == "thumbnail.jpg":
            return f"api/events/{event_id}/thumbnail.jpg"

        if path == "snapshot.jpg":
            return f"api/events/{event_id}/snapshot.jpg"

        if path.endswith("clip.mp4"):
            return f"api/events/{event_id}/clip.mp4"
        return None

    def _permit_request(self, request: web.Request, config_entry: ConfigEntry) -> bool:
        """Determine whether to permit a request."""

        return bool(config_entry.options.get(CONF_NOTIFICATION_PROXY_ENABLE, True))