"""Storage for gated documents.

Rooted OUTSIDE any web-served path, with no ``base_url`` — so a stored file has
no public URL at all (``.url()`` raises by design). Files reach users only
through the authenticated download view. The location is read from settings
live, so it honours per-instance configuration and test overrides rather than
baking a path into migrations.
"""
import os

from django.conf import settings
from django.core.files.storage import FileSystemStorage


class PrivateMediaStorage(FileSystemStorage):
    @property
    def base_location(self):
        return os.fspath(settings.PRIVATE_MEDIA_ROOT)

    @property
    def location(self):
        return os.path.abspath(self.base_location)

    @property
    def base_url(self):
        # No public URL. Storage.url() raises ValueError when base_url is None.
        return None


def private_storage():
    """Callable storage for FileField(storage=...): evaluated once at model load,
    but reads the live setting on every operation."""
    return PrivateMediaStorage()
