from typing import Any, Dict, List, Type, TypeVar, Union

import attr

from ..models.event_protocols import EventProtocols
from ..models.fs_event_action import FsEventAction
from ..models.fs_event_status import FsEventStatus
from ..models.fs_providers import FsProviders
from ..types import UNSET, Unset

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


@attr.s(auto_attribs=True)
class FsEvent:
    """
    Attributes:
        id (Union[Unset, str]):
        timestamp (Union[Unset, int]): unix timestamp in nanoseconds
        action (Union[Unset, FsEventAction]):
        username (Union[Unset, str]):
        fs_path (Union[Unset, str]):
        fs_target_path (Union[Unset, str]):
        virtual_path (Union[Unset, str]):
        virtual_target_path (Union[Unset, str]):
        ssh_cmd (Union[Unset, str]):
        file_size (Union[Unset, int]):
        status (Union[Unset, FsEventStatus]): Event status:
              * `1` - no error
              * `2` - generic error
              * `3` - quota exceeded error
        protocol (Union[Unset, EventProtocols]): Protocols:
              * `SSH` - SSH commands
              * `SFTP` - SFTP protocol
              * `FTP` - plain FTP and FTPES/FTPS
              * `DAV` - WebDAV
              * `HTTP` - WebClient/REST API
              * `HTTPShare` - the event is generated in a public share
              * `DataRetention` - the event is generated by a data retention check
              * `OIDC` - OpenID Connect
        ip (Union[Unset, str]):
        session_id (Union[Unset, str]):
        fs_provider (Union[Unset, FsProviders]): Filesystem providers:
              * `0` - Local filesystem
              * `1` - S3 Compatible Object Storage
              * `2` - Google Cloud Storage
              * `3` - Azure Blob Storage
              * `4` - Local filesystem encrypted
              * `5` - SFTP
        bucket (Union[Unset, str]):
        endpoint (Union[Unset, str]):
        open_flags (Union[Unset, str]):
        instance_id (Union[Unset, str]):
    """

    id: Union[Unset, str] = UNSET
    timestamp: Union[Unset, int] = UNSET
    action: Union[Unset, FsEventAction] = UNSET
    username: Union[Unset, str] = UNSET
    fs_path: Union[Unset, str] = UNSET
    fs_target_path: Union[Unset, str] = UNSET
    virtual_path: Union[Unset, str] = UNSET
    virtual_target_path: Union[Unset, str] = UNSET
    ssh_cmd: Union[Unset, str] = UNSET
    file_size: Union[Unset, int] = UNSET
    status: Union[Unset, FsEventStatus] = UNSET
    protocol: Union[Unset, EventProtocols] = UNSET
    ip: Union[Unset, str] = UNSET
    session_id: Union[Unset, str] = UNSET
    fs_provider: Union[Unset, FsProviders] = UNSET
    bucket: Union[Unset, str] = UNSET
    endpoint: Union[Unset, str] = UNSET
    open_flags: Union[Unset, str] = UNSET
    instance_id: Union[Unset, str] = UNSET
    additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

    def to_dict(self) -> Dict[str, Any]:
        id = self.id
        timestamp = self.timestamp
        action: Union[Unset, str] = UNSET
        if not isinstance(self.action, Unset):
            action = self.action.value

        username = self.username
        fs_path = self.fs_path
        fs_target_path = self.fs_target_path
        virtual_path = self.virtual_path
        virtual_target_path = self.virtual_target_path
        ssh_cmd = self.ssh_cmd
        file_size = self.file_size
        status: Union[Unset, int] = UNSET
        if not isinstance(self.status, Unset):
            status = self.status.value

        protocol: Union[Unset, str] = UNSET
        if not isinstance(self.protocol, Unset):
            protocol = self.protocol.value

        ip = self.ip
        session_id = self.session_id
        fs_provider: Union[Unset, int] = UNSET
        if not isinstance(self.fs_provider, Unset):
            fs_provider = self.fs_provider.value

        bucket = self.bucket
        endpoint = self.endpoint
        open_flags = self.open_flags
        instance_id = self.instance_id

        field_dict: Dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if id is not UNSET:
            field_dict["id"] = id
        if timestamp is not UNSET:
            field_dict["timestamp"] = timestamp
        if action is not UNSET:
            field_dict["action"] = action
        if username is not UNSET:
            field_dict["username"] = username
        if fs_path is not UNSET:
            field_dict["fs_path"] = fs_path
        if fs_target_path is not UNSET:
            field_dict["fs_target_path"] = fs_target_path
        if virtual_path is not UNSET:
            field_dict["virtual_path"] = virtual_path
        if virtual_target_path is not UNSET:
            field_dict["virtual_target_path"] = virtual_target_path
        if ssh_cmd is not UNSET:
            field_dict["ssh_cmd"] = ssh_cmd
        if file_size is not UNSET:
            field_dict["file_size"] = file_size
        if status is not UNSET:
            field_dict["status"] = status
        if protocol is not UNSET:
            field_dict["protocol"] = protocol
        if ip is not UNSET:
            field_dict["ip"] = ip
        if session_id is not UNSET:
            field_dict["session_id"] = session_id
        if fs_provider is not UNSET:
            field_dict["fs_provider"] = fs_provider
        if bucket is not UNSET:
            field_dict["bucket"] = bucket
        if endpoint is not UNSET:
            field_dict["endpoint"] = endpoint
        if open_flags is not UNSET:
            field_dict["open_flags"] = open_flags
        if instance_id is not UNSET:
            field_dict["instance_id"] = instance_id

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
        d = src_dict.copy()
        id = d.pop("id", UNSET)

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

        _action = d.pop("action", UNSET)
        action: Union[Unset, FsEventAction]
        if isinstance(_action, Unset):
            action = UNSET
        else:
            action = FsEventAction(_action)

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

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

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

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

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

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

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

        _status = d.pop("status", UNSET)
        status: Union[Unset, FsEventStatus]
        if isinstance(_status, Unset):
            status = UNSET
        else:
            status = FsEventStatus(_status)

        _protocol = d.pop("protocol", UNSET)
        protocol: Union[Unset, EventProtocols]
        if isinstance(_protocol, Unset):
            protocol = UNSET
        else:
            protocol = EventProtocols(_protocol)

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

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

        _fs_provider = d.pop("fs_provider", UNSET)
        fs_provider: Union[Unset, FsProviders]
        if isinstance(_fs_provider, Unset):
            fs_provider = UNSET
        else:
            fs_provider = FsProviders(_fs_provider)

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

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

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

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

        fs_event = cls(
            id=id,
            timestamp=timestamp,
            action=action,
            username=username,
            fs_path=fs_path,
            fs_target_path=fs_target_path,
            virtual_path=virtual_path,
            virtual_target_path=virtual_target_path,
            ssh_cmd=ssh_cmd,
            file_size=file_size,
            status=status,
            protocol=protocol,
            ip=ip,
            session_id=session_id,
            fs_provider=fs_provider,
            bucket=bucket,
            endpoint=endpoint,
            open_flags=open_flags,
            instance_id=instance_id,
        )

        fs_event.additional_properties = d
        return fs_event

    @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
