from __future__ import annotations

from abc import abstractmethod
from types import TracebackType
from typing import Self

from fastapi import Request
from starlette.responses import Response

from pygitweb.api.plugin import Plugin


class Action(Plugin):
	"""
	Action: A per-project action provided by a plugin.

	``project`` is the project path/slug as used in URLs (under PROJECTROOT).
	"""

	@abstractmethod
	def __enter__(self) -> Self: ...

	@abstractmethod
	def __exit__(
		self,
		exc_type: type[BaseException] | None,
		exc_value: BaseException | None,
		traceback: TracebackType | None,
	) -> bool | None: ...

	@abstractmethod
	def action_name(self) -> str: ...

	@abstractmethod
	def action(self, project: str, req: Request | None = None) -> Response | None: ...