"""OpenAPI core validation request datatypes module"""

from dataclasses import dataclass
from dataclasses import field
from typing import Any
from typing import Mapping
from typing import Union

from werkzeug.datastructures import Headers
from werkzeug.datastructures import ImmutableMultiDict

# Type alias for headers that accepts both Mapping and werkzeug Headers
HeadersType = Union[Mapping[str, Any], Headers]


@dataclass
class RequestParameters:
    """OpenAPI request parameters dataclass.

    Attributes:
        query
            Query string parameters as MultiDict. Must support getlist method.
        header
            Request headers as Headers.
        cookie
            Request cookies as MultiDict.
        path
            Path parameters as dict. Gets resolved against spec if empty.
    """

    query: Mapping[str, Any] = field(default_factory=ImmutableMultiDict)
    header: HeadersType = field(default_factory=Headers)
    cookie: Mapping[str, Any] = field(default_factory=ImmutableMultiDict)
    path: Mapping[str, Any] = field(default_factory=dict)

    def __getitem__(self, location: str) -> Any:
        return getattr(self, location)


@dataclass
class Parameters:
    query: Mapping[str, Any] = field(default_factory=dict)
    header: Mapping[str, Any] = field(default_factory=dict)
    cookie: Mapping[str, Any] = field(default_factory=dict)
    path: Mapping[str, Any] = field(default_factory=dict)
