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

from typing import Any

import httpx

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


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, *, older_than: str | None=None, statuses: list | None=None, dry_run: bool | None=None, limit: int | None=None) -> AdminPurgeJobsResponse:
        """Purge completed background jobs

        Deletes terminal background jobs older than a retention cutoff.

        Args:
            older_than (str, optional): ISO-8601 timestamp cutoff; only terminal jobs older than this instant are eligible.
            statuses (list, optional): Optional terminal background job statuses to target for purging.
            dry_run (bool, optional): If true, report purge counts without deleting any rows.
            limit (int, optional): Maximum number of jobs to purge in this request.

        Returns:
            AdminPurgeJobsResponse
        """
        _params: dict = {}
        if older_than is not None:
            _params['older_than'] = older_than
        if statuses is not None:
            _params['statuses'] = statuses
        if dry_run is not None:
            _params['dry_run'] = dry_run
        if limit is not None:
            _params['limit'] = limit
        body = AdminPurgeJobsRequest.model_validate(_params) if _params 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, *, older_than: str | None=None, statuses: list | None=None, dry_run: bool | None=None, limit: int | None=None) -> AdminPurgeJobsResponse:
        """Purge completed background jobs

        Deletes terminal background jobs older than a retention cutoff.

        Args:
            older_than (str, optional): ISO-8601 timestamp cutoff; only terminal jobs older than this instant are eligible.
            statuses (list, optional): Optional terminal background job statuses to target for purging.
            dry_run (bool, optional): If true, report purge counts without deleting any rows.
            limit (int, optional): Maximum number of jobs to purge in this request.

        Returns:
            AdminPurgeJobsResponse
        """
        _params: dict = {}
        if older_than is not None:
            _params['older_than'] = older_than
        if statuses is not None:
            _params['statuses'] = statuses
        if dry_run is not None:
            _params['dry_run'] = dry_run
        if limit is not None:
            _params['limit'] = limit
        body = AdminPurgeJobsRequest.model_validate(_params) if _params 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', 'input_shape': 'kwargs_body', 'summary': 'Purge completed background jobs', 'description': 'Deletes terminal background jobs older than a retention cutoff.', 'response': 'AdminPurgeJobsResponse', 'params': [{'name': 'older_than', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'olderThan', 'description': 'ISO-8601 timestamp cutoff; only terminal jobs older than this instant are eligible.'}, {'name': 'statuses', 'type': 'list[str]', 'source': 'body', 'required': False, 'description': 'Optional terminal background job statuses to target for purging.'}, {'name': 'dry_run', 'type': 'bool', 'source': 'body', 'required': False, 'alias': 'dryRun', 'description': 'If true, report purge counts without deleting any rows.'}, {'name': 'limit', 'type': 'int', 'source': 'body', 'required': False, 'description': 'Maximum number of jobs to purge in this request.'}], 'body_model': 'AdminPurgeJobsRequest', 'body_expr': 'AdminPurgeJobsRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}, 'license.reload': {'http_method': 'POST', 'path': '/v1/admin/license:reload', 'input_shape': 'no_params', 'summary': 'Reload the active license from disk', 'description': 'Triggers the server to reload its license file from the configured directory and returns metadata about the currently active license.', 'response': 'AdminReloadLicenseResponse'}, 'drain': {'http_method': 'POST', 'path': '/v1/admin:drain', 'input_shape': 'kwargs_body', 'summary': 'Request the server to enter drain mode', 'description': 'Initiates drain mode and optionally waits for the server to quiesce.', 'response': 'AdminDrainResponse', 'params': [{'name': 'timeout_sec', 'type': 'int', 'source': 'body', 'required': False, 'alias': 'timeoutSec', 'description': 'Maximum seconds to wait for the server to quiesce before returning.'}, {'name': 'reason', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Human-readable reason for initiating drain mode.'}, {'name': 'wait_for_quiesce', 'type': 'bool', 'source': 'body', 'required': False, 'alias': 'waitForQuiesce', 'description': 'If true, wait for in-flight requests to complete and the server to reach QUIESCED before responding.'}], '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, *, timeout_sec: int | None=None, reason: str | None=None, wait_for_quiesce: bool | None=None) -> AdminDrainResponse:
        """Request the server to enter drain mode

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

        Args:
            timeout_sec (int, optional): Maximum seconds to wait for the server to quiesce before returning.
            reason (str, optional): Human-readable reason for initiating drain mode.
            wait_for_quiesce (bool, optional): If true, wait for in-flight requests to complete and the server to reach QUIESCED before responding.

        Returns:
            AdminDrainResponse
        """
        _params: dict = {}
        if timeout_sec is not None:
            _params['timeout_sec'] = timeout_sec
        if reason is not None:
            _params['reason'] = reason
        if wait_for_quiesce is not None:
            _params['wait_for_quiesce'] = wait_for_quiesce
        body = AdminDrainRequest.model_validate(_params) if _params 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', 'input_shape': 'kwargs_body', 'summary': 'Purge completed background jobs', 'description': 'Deletes terminal background jobs older than a retention cutoff.', 'response': 'AdminPurgeJobsResponse', 'params': [{'name': 'older_than', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'olderThan', 'description': 'ISO-8601 timestamp cutoff; only terminal jobs older than this instant are eligible.'}, {'name': 'statuses', 'type': 'list[str]', 'source': 'body', 'required': False, 'description': 'Optional terminal background job statuses to target for purging.'}, {'name': 'dry_run', 'type': 'bool', 'source': 'body', 'required': False, 'alias': 'dryRun', 'description': 'If true, report purge counts without deleting any rows.'}, {'name': 'limit', 'type': 'int', 'source': 'body', 'required': False, 'description': 'Maximum number of jobs to purge in this request.'}], 'body_model': 'AdminPurgeJobsRequest', 'body_expr': 'AdminPurgeJobsRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}, 'license.reload': {'http_method': 'POST', 'path': '/v1/admin/license:reload', 'input_shape': 'no_params', 'summary': 'Reload the active license from disk', 'description': 'Triggers the server to reload its license file from the configured directory and returns metadata about the currently active license.', 'response': 'AdminReloadLicenseResponse'}, 'drain': {'http_method': 'POST', 'path': '/v1/admin:drain', 'input_shape': 'kwargs_body', 'summary': 'Request the server to enter drain mode', 'description': 'Initiates drain mode and optionally waits for the server to quiesce.', 'response': 'AdminDrainResponse', 'params': [{'name': 'timeout_sec', 'type': 'int', 'source': 'body', 'required': False, 'alias': 'timeoutSec', 'description': 'Maximum seconds to wait for the server to quiesce before returning.'}, {'name': 'reason', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Human-readable reason for initiating drain mode.'}, {'name': 'wait_for_quiesce', 'type': 'bool', 'source': 'body', 'required': False, 'alias': 'waitForQuiesce', 'description': 'If true, wait for in-flight requests to complete and the server to reach QUIESCED before responding.'}], '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, *, timeout_sec: int | None=None, reason: str | None=None, wait_for_quiesce: bool | None=None) -> AdminDrainResponse:
        """Request the server to enter drain mode

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

        Args:
            timeout_sec (int, optional): Maximum seconds to wait for the server to quiesce before returning.
            reason (str, optional): Human-readable reason for initiating drain mode.
            wait_for_quiesce (bool, optional): If true, wait for in-flight requests to complete and the server to reach QUIESCED before responding.

        Returns:
            AdminDrainResponse
        """
        _params: dict = {}
        if timeout_sec is not None:
            _params['timeout_sec'] = timeout_sec
        if reason is not None:
            _params['reason'] = reason
        if wait_for_quiesce is not None:
            _params['wait_for_quiesce'] = wait_for_quiesce
        body = AdminDrainRequest.model_validate(_params) if _params 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())

