# This file was auto-generated by Fern from our API Definition.

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.mini_chat_settings_payload import MiniChatSettingsPayload
from ..types.mini_chat_settings_response import MiniChatSettingsResponse
from .raw_client import AsyncRawUserPreferencesClient, RawUserPreferencesClient

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class UserPreferencesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawUserPreferencesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawUserPreferencesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawUserPreferencesClient
        """
        return self._raw_client

    def get_mini_chat_settings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MiniChatSettingsResponse:
        """
        Retrieve the authenticated user's mini chat bar settings.

        **First-run behaviour:** If no settings have been saved yet, the server
        auto-provisions canonical defaults and returns them with `revision: 1`.
        The endpoint **always** returns `200`; it never returns `404`.

        **Response envelope:**

        ```json
        {
          "data": {
            "settings": { ... },
            "revision": 1,
            "updatedAt": "2026-03-02T09:30:00Z"
          }
        }
        ```

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MiniChatSettingsResponse
            Settings retrieved (or auto-provisioned on first access)

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.user_preferences.get_mini_chat_settings()
        """
        _response = self._raw_client.get_mini_chat_settings(request_options=request_options)
        return _response.data

    def upsert_mini_chat_settings(
        self,
        *,
        settings: MiniChatSettingsPayload,
        revision: int,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MiniChatSettingsResponse:
        """
        Create or update the authenticated user's mini chat bar settings using
        **optimistic concurrency** based on a monotonic `revision` counter.

        ### Request

        | Field | Type | Required | Description |
        |-------|------|----------|-------------|
        | `settings` | object | yes | Full settings object (missing fields default to canonical values) |
        | `revision` | integer | yes | The revision the client last read; must match server's current revision |

        ### Settings fields

        | Field | Type | Allowed values | Default |
        |-------|------|----------------|---------|
        | `position` | string | `bottom-right`, `bottom-left`, `top-right`, `top-left`, `bottom-center`, `top-center` | `bottom-center` |
        | `resetToNewChat` | string | `never`, `10m`, `30m`, `60m` | `10m` |
        | `keyboardShortcut` | string | any string (trimmed; whitespace-only becomes `""`) | `CommandOrControl+K` |
        | `openNewChats` | string | `companion-chat`, `main-window` | `companion-chat` |
        | `assistantSelection` | string | `default`, `last-used` | `default` |

        ### Conflict handling

        If the client sends a stale `revision`, the server responds with **409**
        and includes the latest canonical state in `error.details.latest` so the
        client can re-hydrate without an extra GET.

        ### Normalization

        - Unknown fields in `settings` are silently ignored.
        - Missing fields are filled with defaults (full-replace semantics).
        - `keyboardShortcut` is trimmed; whitespace-only becomes `""`.

        Parameters
        ----------
        settings : MiniChatSettingsPayload
            Full settings object (missing fields filled with defaults)

        revision : int
            Expected current revision for optimistic concurrency. Send 0 when writing for the first time (no prior GET).

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MiniChatSettingsResponse
            Settings saved successfully

        Examples
        --------
        from aitronos import Aitronos, MiniChatSettingsPayload

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.user_preferences.upsert_mini_chat_settings(
            settings=MiniChatSettingsPayload(),
            revision=1,
        )
        """
        _response = self._raw_client.upsert_mini_chat_settings(
            settings=settings, revision=revision, request_options=request_options
        )
        return _response.data


class AsyncUserPreferencesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawUserPreferencesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawUserPreferencesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawUserPreferencesClient
        """
        return self._raw_client

    async def get_mini_chat_settings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MiniChatSettingsResponse:
        """
        Retrieve the authenticated user's mini chat bar settings.

        **First-run behaviour:** If no settings have been saved yet, the server
        auto-provisions canonical defaults and returns them with `revision: 1`.
        The endpoint **always** returns `200`; it never returns `404`.

        **Response envelope:**

        ```json
        {
          "data": {
            "settings": { ... },
            "revision": 1,
            "updatedAt": "2026-03-02T09:30:00Z"
          }
        }
        ```

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MiniChatSettingsResponse
            Settings retrieved (or auto-provisioned on first access)

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.user_preferences.get_mini_chat_settings()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_mini_chat_settings(request_options=request_options)
        return _response.data

    async def upsert_mini_chat_settings(
        self,
        *,
        settings: MiniChatSettingsPayload,
        revision: int,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MiniChatSettingsResponse:
        """
        Create or update the authenticated user's mini chat bar settings using
        **optimistic concurrency** based on a monotonic `revision` counter.

        ### Request

        | Field | Type | Required | Description |
        |-------|------|----------|-------------|
        | `settings` | object | yes | Full settings object (missing fields default to canonical values) |
        | `revision` | integer | yes | The revision the client last read; must match server's current revision |

        ### Settings fields

        | Field | Type | Allowed values | Default |
        |-------|------|----------------|---------|
        | `position` | string | `bottom-right`, `bottom-left`, `top-right`, `top-left`, `bottom-center`, `top-center` | `bottom-center` |
        | `resetToNewChat` | string | `never`, `10m`, `30m`, `60m` | `10m` |
        | `keyboardShortcut` | string | any string (trimmed; whitespace-only becomes `""`) | `CommandOrControl+K` |
        | `openNewChats` | string | `companion-chat`, `main-window` | `companion-chat` |
        | `assistantSelection` | string | `default`, `last-used` | `default` |

        ### Conflict handling

        If the client sends a stale `revision`, the server responds with **409**
        and includes the latest canonical state in `error.details.latest` so the
        client can re-hydrate without an extra GET.

        ### Normalization

        - Unknown fields in `settings` are silently ignored.
        - Missing fields are filled with defaults (full-replace semantics).
        - `keyboardShortcut` is trimmed; whitespace-only becomes `""`.

        Parameters
        ----------
        settings : MiniChatSettingsPayload
            Full settings object (missing fields filled with defaults)

        revision : int
            Expected current revision for optimistic concurrency. Send 0 when writing for the first time (no prior GET).

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        MiniChatSettingsResponse
            Settings saved successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos, MiniChatSettingsPayload

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.user_preferences.upsert_mini_chat_settings(
                settings=MiniChatSettingsPayload(),
                revision=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.upsert_mini_chat_settings(
            settings=settings, revision=revision, request_options=request_options
        )
        return _response.data
