# DO NOT EDIT — generated by _sdk_gen/ from the OpenAPI spec.
# Regenerate with: ./generate.sh
from __future__ import annotations

from typing import Any

import httpx

from goodmem._generated.models.admin_drain_request import AdminDrainRequest
from goodmem._generated.models.admin_drain_response import AdminDrainResponse
from goodmem._generated.models.admin_purge_jobs_request import AdminPurgeJobsRequest
from goodmem._generated.models.admin_purge_jobs_response import AdminPurgeJobsResponse
from goodmem._generated.models.admin_reload_license_response import AdminReloadLicenseResponse
from goodmem.errors import raise_for_status


class _AdminBackgroundJobsNamespace:
    """Sub-namespace for admin background-jobs operations."""

    def __init__(self, http: httpx.Client, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers

    def purge(self, **kwargs: Any) -> AdminPurgeJobsResponse:
        """Purge completed background jobs

        Deletes terminal background jobs older than a retention cutoff.

        Args:
            older_than (string, optional): Older than
            statuses (array, optional): Statuses
            dry_run (boolean, optional): Dry run
            limit (integer, optional): Limit

        Returns:
            AdminPurgeJobsResponse
        """
        body = AdminPurgeJobsRequest.model_validate(kwargs) if kwargs else None
        resp = self._http.post(
            "/v1/admin/background-jobs:purge",
            json=body.model_dump(by_alias=True, exclude_unset=True) if body else None,
            headers=self._headers,
        )
        raise_for_status(resp)
        return AdminPurgeJobsResponse.model_validate(resp.json())



class _AsyncAdminBackgroundJobsNamespace:
    """Async sub-namespace for admin background-jobs operations."""

    def __init__(self, http: httpx.AsyncClient, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers

    async def purge(self, **kwargs: Any) -> AdminPurgeJobsResponse:
        """Purge completed background jobs

        Deletes terminal background jobs older than a retention cutoff.

        Args:
            older_than (string, optional): Older than
            statuses (array, optional): Statuses
            dry_run (boolean, optional): Dry run
            limit (integer, optional): Limit

        Returns:
            AdminPurgeJobsResponse
        """
        body = AdminPurgeJobsRequest.model_validate(kwargs) if kwargs else None
        resp = await self._http.post(
            "/v1/admin/background-jobs:purge",
            json=body.model_dump(by_alias=True, exclude_unset=True) if body else None,
            headers=self._headers,
        )
        raise_for_status(resp)
        return AdminPurgeJobsResponse.model_validate(resp.json())



class _AdminLicenseNamespace:
    """Sub-namespace for admin license operations."""

    def __init__(self, http: httpx.Client, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers

    def reload(self) -> AdminReloadLicenseResponse:
        """Reload the active license from disk

        Triggers the server to reload its license file from the configured directory and returns metadata about the currently active license.

        Returns:
            AdminReloadLicenseResponse
        """
        resp = self._http.post(
            "/v1/admin/license:reload",
            headers=self._headers,
        )
        raise_for_status(resp)
        return AdminReloadLicenseResponse.model_validate(resp.json())



class _AsyncAdminLicenseNamespace:
    """Async sub-namespace for admin license operations."""

    def __init__(self, http: httpx.AsyncClient, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers

    async def reload(self) -> AdminReloadLicenseResponse:
        """Reload the active license from disk

        Triggers the server to reload its license file from the configured directory and returns metadata about the currently active license.

        Returns:
            AdminReloadLicenseResponse
        """
        resp = await self._http.post(
            "/v1/admin/license:reload",
            headers=self._headers,
        )
        raise_for_status(resp)
        return AdminReloadLicenseResponse.model_validate(resp.json())



class AdminAPIBase:
    """Admin API — auto-generated structural base.

    Auto-generated structural base. Do not edit.
    Override in goodmem/api/admin.py to add domain-specific logic.

    Sub-namespaces:
        background_jobs: purge()
        license: reload()
    """

    _rest_metadata: dict = {'background_jobs.purge': {'http_method': 'POST', 'path': '/v1/admin/background-jobs:purge', 'response': 'AdminPurgeJobsResponse', 'body_model': 'AdminPurgeJobsRequest', 'body_expr': 'AdminPurgeJobsRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}, 'license.reload': {'http_method': 'POST', 'path': '/v1/admin/license:reload', 'response': 'AdminReloadLicenseResponse'}, 'drain': {'http_method': 'POST', 'path': '/v1/admin:drain', 'response': 'AdminDrainResponse', 'body_model': 'AdminDrainRequest', 'body_expr': 'AdminDrainRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}}

    def __init__(self, http: httpx.Client, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers
        self.background_jobs = _AdminBackgroundJobsNamespace(http, headers)
        self.license = _AdminLicenseNamespace(http, headers)

    def drain(self, **kwargs: Any) -> AdminDrainResponse:
        """Request the server to enter drain mode

        Initiates drain mode and optionally waits for the server to quiesce.

        Args:
            timeout_sec (integer, optional): Timeout sec
            reason (string, optional): Reason
            wait_for_quiesce (boolean, optional): Wait for quiesce

        Returns:
            AdminDrainResponse
        """
        body = AdminDrainRequest.model_validate(kwargs) if kwargs else None
        resp = self._http.post(
            "/v1/admin:drain",
            json=body.model_dump(by_alias=True, exclude_unset=True) if body else None,
            headers=self._headers,
        )
        raise_for_status(resp)
        return AdminDrainResponse.model_validate(resp.json())


class AsyncAdminAPIBase:
    """Async Admin API — auto-generated structural base.

    Auto-generated structural base. Do not edit.
    Override in goodmem/api/admin.py to add domain-specific logic.

    Sub-namespaces:
        background_jobs: purge()
        license: reload()
    """

    _rest_metadata: dict = {'background_jobs.purge': {'http_method': 'POST', 'path': '/v1/admin/background-jobs:purge', 'response': 'AdminPurgeJobsResponse', 'body_model': 'AdminPurgeJobsRequest', 'body_expr': 'AdminPurgeJobsRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}, 'license.reload': {'http_method': 'POST', 'path': '/v1/admin/license:reload', 'response': 'AdminReloadLicenseResponse'}, 'drain': {'http_method': 'POST', 'path': '/v1/admin:drain', 'response': 'AdminDrainResponse', 'body_model': 'AdminDrainRequest', 'body_expr': 'AdminDrainRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}}

    def __init__(self, http: httpx.AsyncClient, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers
        self.background_jobs = _AsyncAdminBackgroundJobsNamespace(http, headers)
        self.license = _AsyncAdminLicenseNamespace(http, headers)

    async def drain(self, **kwargs: Any) -> AdminDrainResponse:
        """Request the server to enter drain mode

        Initiates drain mode and optionally waits for the server to quiesce.

        Args:
            timeout_sec (integer, optional): Timeout sec
            reason (string, optional): Reason
            wait_for_quiesce (boolean, optional): Wait for quiesce

        Returns:
            AdminDrainResponse
        """
        body = AdminDrainRequest.model_validate(kwargs) if kwargs else None
        resp = await self._http.post(
            "/v1/admin:drain",
            json=body.model_dump(by_alias=True, exclude_unset=True) if body else None,
            headers=self._headers,
        )
        raise_for_status(resp)
        return AdminDrainResponse.model_validate(resp.json())

