from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, cast

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

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.types_activity import TypesActivity
    from ..models.types_track import TypesTrack


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


@_attrs_define
class TypesCampaign:
    """
    Attributes:
        field_id (str | Unset):
        activity (list[TypesActivity] | Unset): For returning
        clicks (int | Unset): Cached data
        created_at (str | Unset):
        deleted_at (str | Unset):
        manager (str | Unset):
        name (str | Unset):
        notes (str | Unset):
        opens (int | Unset):
        redirect (str | Unset):
        resource (str | Unset):
        tags (list[str] | Unset):
        team (str | Unset):
        tracks (list[TypesTrack] | Unset):
        type_ (str | Unset):
    """

    field_id: str | Unset = UNSET
    activity: list[TypesActivity] | Unset = UNSET
    clicks: int | Unset = UNSET
    created_at: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    manager: str | Unset = UNSET
    name: str | Unset = UNSET
    notes: str | Unset = UNSET
    opens: int | Unset = UNSET
    redirect: str | Unset = UNSET
    resource: str | Unset = UNSET
    tags: list[str] | Unset = UNSET
    team: str | Unset = UNSET
    tracks: list[TypesTrack] | Unset = UNSET
    type_: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        activity: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.activity, Unset):
            activity = []
            for activity_item_data in self.activity:
                activity_item = activity_item_data.to_dict()
                activity.append(activity_item)

        clicks = self.clicks

        created_at = self.created_at

        deleted_at = self.deleted_at

        manager = self.manager

        name = self.name

        notes = self.notes

        opens = self.opens

        redirect = self.redirect

        resource = self.resource

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

        team = self.team

        tracks: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.tracks, Unset):
            tracks = []
            for tracks_item_data in self.tracks:
                tracks_item = tracks_item_data.to_dict()
                tracks.append(tracks_item)

        type_ = self.type_

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field_id is not UNSET:
            field_dict["_id"] = field_id
        if activity is not UNSET:
            field_dict["activity"] = activity
        if clicks is not UNSET:
            field_dict["clicks"] = clicks
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if manager is not UNSET:
            field_dict["manager"] = manager
        if name is not UNSET:
            field_dict["name"] = name
        if notes is not UNSET:
            field_dict["notes"] = notes
        if opens is not UNSET:
            field_dict["opens"] = opens
        if redirect is not UNSET:
            field_dict["redirect"] = redirect
        if resource is not UNSET:
            field_dict["resource"] = resource
        if tags is not UNSET:
            field_dict["tags"] = tags
        if team is not UNSET:
            field_dict["team"] = team
        if tracks is not UNSET:
            field_dict["tracks"] = tracks
        if type_ is not UNSET:
            field_dict["type"] = type_

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_activity import TypesActivity
        from ..models.types_track import TypesTrack

        d = dict(src_dict)
        field_id = d.pop("_id", UNSET)

        _activity = d.pop("activity", UNSET)
        activity: list[TypesActivity] | Unset = UNSET
        if _activity is not UNSET:
            activity = []
            for activity_item_data in _activity:
                activity_item = TypesActivity.from_dict(activity_item_data)

                activity.append(activity_item)

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

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

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

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

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

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

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

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

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

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

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

        _tracks = d.pop("tracks", UNSET)
        tracks: list[TypesTrack] | Unset = UNSET
        if _tracks is not UNSET:
            tracks = []
            for tracks_item_data in _tracks:
                tracks_item = TypesTrack.from_dict(tracks_item_data)

                tracks.append(tracks_item)

        type_ = d.pop("type", UNSET)

        types_campaign = cls(
            field_id=field_id,
            activity=activity,
            clicks=clicks,
            created_at=created_at,
            deleted_at=deleted_at,
            manager=manager,
            name=name,
            notes=notes,
            opens=opens,
            redirect=redirect,
            resource=resource,
            tags=tags,
            team=team,
            tracks=tracks,
            type_=type_,
        )

        types_campaign.additional_properties = d
        return types_campaign

    @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
