from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, BinaryIO, TextIO, TYPE_CHECKING, Generator

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

from ..models.transport import Transport
from ..types import UNSET, Unset
from typing import cast

if TYPE_CHECKING:
  from ..models.renderer_config import RendererConfig





T = TypeVar("T", bound="SourceCreate")



@_attrs_define
class SourceCreate:
    """ Request body for adding a source to a context.

        Example:
            {'transport': 'ssh', 'location': 'hostA:/path/to/docs', 'alias': 'hostA-docs'}

        Attributes:
            transport (Transport): Transport mechanism for a source.
            location (str):
            alias (str | Unset):
            renderer (RendererConfig | Unset): Renderer configuration for Markdown-to-HTML conversion. Both engines are
                optional; partial overrides are allowed (set only `md_engine` or only
                `hl_engine`). When neither context nor source sets a value, the service
                default applies (`md_engine: "pandoc"`, `hl_engine: "pygments"`). Example: {'md_engine': 'pandoc', 'hl_engine':
                'pygments'}.
     """

    transport: Transport
    location: str
    alias: str | Unset = UNSET
    renderer: RendererConfig | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)





    def to_dict(self) -> dict[str, Any]:
        from ..models.renderer_config import RendererConfig
        transport = self.transport.value

        location = self.location

        alias = self.alias

        renderer: dict[str, Any] | Unset = UNSET
        if not isinstance(self.renderer, Unset):
            renderer = self.renderer.to_dict()


        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({
            "transport": transport,
            "location": location,
        })
        if alias is not UNSET:
            field_dict["alias"] = alias
        if renderer is not UNSET:
            field_dict["renderer"] = renderer

        return field_dict



    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.renderer_config import RendererConfig
        d = dict(src_dict)
        transport = Transport(d.pop("transport"))




        location = d.pop("location")

        alias = d.pop("alias", UNSET)

        _renderer = d.pop("renderer", UNSET)
        renderer: RendererConfig | Unset
        if isinstance(_renderer,  Unset):
            renderer = UNSET
        else:
            renderer = RendererConfig.from_dict(_renderer)




        source_create = cls(
            transport=transport,
            location=location,
            alias=alias,
            renderer=renderer,
        )


        source_create.additional_properties = d
        return source_create

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
