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.post_by_org_by_repo_webhook_body_events_item import PostByOrgByRepoWebhookBodyEventsItem
from ..types import UNSET, Unset
from typing import cast






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



@_attrs_define
class PostByOrgByRepoWebhookBody:
    """ 
        Attributes:
            url (str):
            events (list[PostByOrgByRepoWebhookBodyEventsItem] | Unset):
            branches (list[str] | Unset):
            globs (list[str] | Unset):
            secret (str | Unset):
     """

    url: str
    events: list[PostByOrgByRepoWebhookBodyEventsItem] | Unset = UNSET
    branches: list[str] | Unset = UNSET
    globs: list[str] | Unset = UNSET
    secret: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)





    def to_dict(self) -> dict[str, Any]:
        url = self.url

        events: list[str] | Unset = UNSET
        if not isinstance(self.events, Unset):
            events = []
            for events_item_data in self.events:
                events_item = events_item_data.value
                events.append(events_item)



        branches: list[str] | Unset = UNSET
        if not isinstance(self.branches, Unset):
            branches = self.branches



        globs: list[str] | Unset = UNSET
        if not isinstance(self.globs, Unset):
            globs = self.globs



        secret = self.secret


        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({
            "url": url,
        })
        if events is not UNSET:
            field_dict["events"] = events
        if branches is not UNSET:
            field_dict["branches"] = branches
        if globs is not UNSET:
            field_dict["globs"] = globs
        if secret is not UNSET:
            field_dict["secret"] = secret

        return field_dict



    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        url = d.pop("url")

        _events = d.pop("events", UNSET)
        events: list[PostByOrgByRepoWebhookBodyEventsItem] | Unset = UNSET
        if _events is not UNSET:
            events = []
            for events_item_data in _events:
                events_item = PostByOrgByRepoWebhookBodyEventsItem(events_item_data)



                events.append(events_item)


        branches = cast(list[str], d.pop("branches", UNSET))


        globs = cast(list[str], d.pop("globs", UNSET))


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

        post_by_org_by_repo_webhook_body = cls(
            url=url,
            events=events,
            branches=branches,
            globs=globs,
            secret=secret,
        )


        post_by_org_by_repo_webhook_body.additional_properties = d
        return post_by_org_by_repo_webhook_body

    @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
