# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import Literal

import httpx

from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ...._utils import maybe_transform, async_maybe_transform
from .templates import (
    TemplatesResource,
    AsyncTemplatesResource,
    TemplatesResourceWithRawResponse,
    AsyncTemplatesResourceWithRawResponse,
    TemplatesResourceWithStreamingResponse,
    AsyncTemplatesResourceWithStreamingResponse,
)
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import (
    BinaryAPIResponse,
    AsyncBinaryAPIResponse,
    StreamedBinaryAPIResponse,
    AsyncStreamedBinaryAPIResponse,
    to_custom_raw_response_wrapper,
    to_custom_streamed_response_wrapper,
    async_to_custom_raw_response_wrapper,
    async_to_custom_streamed_response_wrapper,
)
from ...._base_client import make_request_options
from ....types.format import v1_create_document_params

__all__ = ["V1Resource", "AsyncV1Resource"]


class V1Resource(SyncAPIResource):
    """Document formatting and template rendering (MD/JSON to PDF/DOCX)"""

    @cached_property
    def templates(self) -> TemplatesResource:
        """Document formatting and template rendering (MD/JSON to PDF/DOCX)"""
        return TemplatesResource(self._client)

    @cached_property
    def with_raw_response(self) -> V1ResourceWithRawResponse:
        """
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/CaseMark/casedev-python#accessing-raw-response-data-eg-headers
        """
        return V1ResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> V1ResourceWithStreamingResponse:
        """
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/CaseMark/casedev-python#with_streaming_response
        """
        return V1ResourceWithStreamingResponse(self)

    def create_document(
        self,
        *,
        content: str,
        output_format: Literal["pdf", "docx", "html_preview"],
        input_format: Literal["md", "json", "text"] | Omit = omit,
        options: v1_create_document_params.Options | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> BinaryAPIResponse:
        """
        Convert Markdown, JSON, or text content to professionally formatted PDF, DOCX,
        or HTML documents. Supports template components with variable interpolation for
        creating consistent legal documents like contracts, briefs, and reports.

        Args:
          content: The source content to format

          output_format: Desired output format

          input_format: Format of the input content

          options: Optional template composition and styling settings used during document
              generation

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        extra_headers = {"Accept": "application/pdf", **(extra_headers or {})}
        return self._post(
            "/format/v1/document",
            body=maybe_transform(
                {
                    "content": content,
                    "output_format": output_format,
                    "input_format": input_format,
                    "options": options,
                },
                v1_create_document_params.V1CreateDocumentParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=BinaryAPIResponse,
        )


class AsyncV1Resource(AsyncAPIResource):
    """Document formatting and template rendering (MD/JSON to PDF/DOCX)"""

    @cached_property
    def templates(self) -> AsyncTemplatesResource:
        """Document formatting and template rendering (MD/JSON to PDF/DOCX)"""
        return AsyncTemplatesResource(self._client)

    @cached_property
    def with_raw_response(self) -> AsyncV1ResourceWithRawResponse:
        """
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/CaseMark/casedev-python#accessing-raw-response-data-eg-headers
        """
        return AsyncV1ResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> AsyncV1ResourceWithStreamingResponse:
        """
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/CaseMark/casedev-python#with_streaming_response
        """
        return AsyncV1ResourceWithStreamingResponse(self)

    async def create_document(
        self,
        *,
        content: str,
        output_format: Literal["pdf", "docx", "html_preview"],
        input_format: Literal["md", "json", "text"] | Omit = omit,
        options: v1_create_document_params.Options | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> AsyncBinaryAPIResponse:
        """
        Convert Markdown, JSON, or text content to professionally formatted PDF, DOCX,
        or HTML documents. Supports template components with variable interpolation for
        creating consistent legal documents like contracts, briefs, and reports.

        Args:
          content: The source content to format

          output_format: Desired output format

          input_format: Format of the input content

          options: Optional template composition and styling settings used during document
              generation

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        extra_headers = {"Accept": "application/pdf", **(extra_headers or {})}
        return await self._post(
            "/format/v1/document",
            body=await async_maybe_transform(
                {
                    "content": content,
                    "output_format": output_format,
                    "input_format": input_format,
                    "options": options,
                },
                v1_create_document_params.V1CreateDocumentParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=AsyncBinaryAPIResponse,
        )


class V1ResourceWithRawResponse:
    def __init__(self, v1: V1Resource) -> None:
        self._v1 = v1

        self.create_document = to_custom_raw_response_wrapper(
            v1.create_document,
            BinaryAPIResponse,
        )

    @cached_property
    def templates(self) -> TemplatesResourceWithRawResponse:
        """Document formatting and template rendering (MD/JSON to PDF/DOCX)"""
        return TemplatesResourceWithRawResponse(self._v1.templates)


class AsyncV1ResourceWithRawResponse:
    def __init__(self, v1: AsyncV1Resource) -> None:
        self._v1 = v1

        self.create_document = async_to_custom_raw_response_wrapper(
            v1.create_document,
            AsyncBinaryAPIResponse,
        )

    @cached_property
    def templates(self) -> AsyncTemplatesResourceWithRawResponse:
        """Document formatting and template rendering (MD/JSON to PDF/DOCX)"""
        return AsyncTemplatesResourceWithRawResponse(self._v1.templates)


class V1ResourceWithStreamingResponse:
    def __init__(self, v1: V1Resource) -> None:
        self._v1 = v1

        self.create_document = to_custom_streamed_response_wrapper(
            v1.create_document,
            StreamedBinaryAPIResponse,
        )

    @cached_property
    def templates(self) -> TemplatesResourceWithStreamingResponse:
        """Document formatting and template rendering (MD/JSON to PDF/DOCX)"""
        return TemplatesResourceWithStreamingResponse(self._v1.templates)


class AsyncV1ResourceWithStreamingResponse:
    def __init__(self, v1: AsyncV1Resource) -> None:
        self._v1 = v1

        self.create_document = async_to_custom_streamed_response_wrapper(
            v1.create_document,
            AsyncStreamedBinaryAPIResponse,
        )

    @cached_property
    def templates(self) -> AsyncTemplatesResourceWithStreamingResponse:
        """Document formatting and template rendering (MD/JSON to PDF/DOCX)"""
        return AsyncTemplatesResourceWithStreamingResponse(self._v1.templates)
