<?php
/**
 * BaseWebhook
 *
 * PHP version 7.3
 *
 * @category Class
 * @package  Pipedrive
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * Pipedrive API v1
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 1.0.0
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 5.3.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace Pipedrive\Model;

use ArrayAccess;
use JsonException;
use JsonSerializable;
use Pipedrive\Traits\RawData;
use Pipedrive\ObjectSerializer;

/**
 * BaseWebhook Class Doc Comment
 *
 * @category Class
 * @package  Pipedrive
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 * @implements ArrayAccess<TKey, TValue>
 * @template TKey int|null
 * @template TValue mixed|null
 */
class BaseWebhook implements ModelInterface, ArrayAccess, JsonSerializable
{
    use RawData;

    public const DISCRIMINATOR = null;

    /**
      * The original name of the model.
      *
      * @var string
      */
    protected static string $openAPIModelName = 'BaseWebhook';

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      * @phpstan-var array<string, string>
      * @phpsalm-var array<string, string>
      */
    protected static array $openAPITypes = [
        'id' => 'int',
        'company_id' => 'int',
        'owner_id' => 'int',
        'user_id' => 'int',
        'event_action' => 'string',
        'event_object' => 'string',
        'subscription_url' => 'string',
        'is_active' => '\Pipedrive\Model\NumberBooleanDefault1',
        'add_time' => '\DateTime',
        'remove_time' => '\DateTime',
        'type' => 'string',
        'http_auth_user' => 'string',
        'http_auth_password' => 'string',
        'additional_data' => 'object',
        'remove_reason' => 'string',
        'last_delivery_time' => '\DateTime',
        'last_http_status' => 'int',
        'admin_id' => 'int'
    ];

    /**
      * Array of property to format mappings. Used for (de)serialization
      *
      * @var string[]
      * @phpstan-var array<string, string|null>
      * @psalm-var array<string, string|null>
      */
    protected static $openAPIFormats = [
        'id' => null,
        'company_id' => null,
        'owner_id' => null,
        'user_id' => null,
        'event_action' => null,
        'event_object' => null,
        'subscription_url' => null,
        'is_active' => null,
        'add_time' => 'date-time',
        'remove_time' => 'date-time',
        'type' => null,
        'http_auth_user' => null,
        'http_auth_password' => null,
        'additional_data' => null,
        'remove_reason' => null,
        'last_delivery_time' => 'date-time',
        'last_http_status' => null,
        'admin_id' => null
    ];

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @phpstan-return array<string, string>
     * @psalm-return array<string, string>
     * @return array
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization
     *
     * @phpstan-return array<string, string|null>
     * @psalm-return array<string, string|null>
     * @return array
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name
     *
     * @var string[]
     */
    protected static $attributeMap = [
        'id' => 'id',
        'company_id' => 'company_id',
        'owner_id' => 'owner_id',
        'user_id' => 'user_id',
        'event_action' => 'event_action',
        'event_object' => 'event_object',
        'subscription_url' => 'subscription_url',
        'is_active' => 'is_active',
        'add_time' => 'add_time',
        'remove_time' => 'remove_time',
        'type' => 'type',
        'http_auth_user' => 'http_auth_user',
        'http_auth_password' => 'http_auth_password',
        'additional_data' => 'additional_data',
        'remove_reason' => 'remove_reason',
        'last_delivery_time' => 'last_delivery_time',
        'last_http_status' => 'last_http_status',
        'admin_id' => 'admin_id'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'id' => 'setId',
        'company_id' => 'setCompanyId',
        'owner_id' => 'setOwnerId',
        'user_id' => 'setUserId',
        'event_action' => 'setEventAction',
        'event_object' => 'setEventObject',
        'subscription_url' => 'setSubscriptionUrl',
        'is_active' => 'setIsActive',
        'add_time' => 'setAddTime',
        'remove_time' => 'setRemoveTime',
        'type' => 'setType',
        'http_auth_user' => 'setHttpAuthUser',
        'http_auth_password' => 'setHttpAuthPassword',
        'additional_data' => 'setAdditionalData',
        'remove_reason' => 'setRemoveReason',
        'last_delivery_time' => 'setLastDeliveryTime',
        'last_http_status' => 'setLastHttpStatus',
        'admin_id' => 'setAdminId'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'id' => 'getId',
        'company_id' => 'getCompanyId',
        'owner_id' => 'getOwnerId',
        'user_id' => 'getUserId',
        'event_action' => 'getEventAction',
        'event_object' => 'getEventObject',
        'subscription_url' => 'getSubscriptionUrl',
        'is_active' => 'getIsActive',
        'add_time' => 'getAddTime',
        'remove_time' => 'getRemoveTime',
        'type' => 'getType',
        'http_auth_user' => 'getHttpAuthUser',
        'http_auth_password' => 'getHttpAuthPassword',
        'additional_data' => 'getAdditionalData',
        'remove_reason' => 'getRemoveReason',
        'last_delivery_time' => 'getLastDeliveryTime',
        'last_http_status' => 'getLastHttpStatus',
        'admin_id' => 'getAdminId'
    ];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name
     *
     * @phpstan-return array<string, string>
     * @psalm-return array<string, string>
     * @return array
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @phpstan-return array<string, string>
     * @psalm-return array<string, string>
     * @return array
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @phpstan-return array<string, string>
     * @psalm-return array<string, string>
     * @return array
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     *
     * @return string
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    const TYPE_GENERAL = 'general';
    const TYPE_APP = 'app';

    /**
     * Gets allowable values of the enum
     *
     * @phpstan-return  array<string|int>
     * @phpsalm-return  array<string|int>
     * @return (string|int)[]
     */
    public function getTypeAllowableValues(): array
    {
        return [
            self::TYPE_GENERAL,
            self::TYPE_APP,
        ];
    }

    /**
     * Associative array for storing property values
     *
     * @var array
     * @phpstan-var array<int|string, mixed>
     * @psalm-var array<int|string, mixed>
     */
    protected array $container = [];

    /**
     * Constructor
     *
     * @phpstan-param array<string, mixed>|null $data
     * @psalm-param array<string, mixed>|null $data
     * @param array|null $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(array $data = null)
    {
        $this->container['id'] = $data['id'] ?? null;
        $this->container['company_id'] = $data['company_id'] ?? null;
        $this->container['owner_id'] = $data['owner_id'] ?? null;
        $this->container['user_id'] = $data['user_id'] ?? null;
        $this->container['event_action'] = $data['event_action'] ?? null;
        $this->container['event_object'] = $data['event_object'] ?? null;
        $this->container['subscription_url'] = $data['subscription_url'] ?? null;
        $this->container['is_active'] = $data['is_active'] ?? null;
        $this->container['add_time'] = $data['add_time'] ?? null;
        $this->container['remove_time'] = $data['remove_time'] ?? null;
        $this->container['type'] = $data['type'] ?? null;
        $this->container['http_auth_user'] = $data['http_auth_user'] ?? null;
        $this->container['http_auth_password'] = $data['http_auth_password'] ?? null;
        $this->container['additional_data'] = $data['additional_data'] ?? null;
        $this->container['remove_reason'] = $data['remove_reason'] ?? null;
        $this->container['last_delivery_time'] = $data['last_delivery_time'] ?? null;
        $this->container['last_http_status'] = $data['last_http_status'] ?? null;
        $this->container['admin_id'] = $data['admin_id'] ?? null;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     * @phpstan-return array<int, string>
     * @psalm-return array<int, string>
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        $allowedValues = $this->getTypeAllowableValues();
        if (!is_null($this->container['type']) && !in_array($this->container['type'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'type', must be one of '%s'",
                $this->container['type'],
                implode("', '", $allowedValues)
            );
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return count($this->listInvalidProperties()) === 0;
    }


    /**
     * Gets id
     *
     * @return int|null
     */
    public function getId()
    {
        return $this->container['id'];
    }

    /**
     * Sets id
     *
     * @param int|null $id The ID of the Webhook
     *
     * @return self
     */
    public function setId($id): self
    {
        $this->container['id'] = $id;

        return $this;
    }

    /**
     * Gets company_id
     *
     * @return int|null
     */
    public function getCompanyId()
    {
        return $this->container['company_id'];
    }

    /**
     * Sets company_id
     *
     * @param int|null $company_id The ID of the company related to the Webhook
     *
     * @return self
     */
    public function setCompanyId($company_id): self
    {
        $this->container['company_id'] = $company_id;

        return $this;
    }

    /**
     * Gets owner_id
     *
     * @return int|null
     */
    public function getOwnerId()
    {
        return $this->container['owner_id'];
    }

    /**
     * Sets owner_id
     *
     * @param int|null $owner_id The ID of the user who owns the Webhook
     *
     * @return self
     */
    public function setOwnerId($owner_id): self
    {
        $this->container['owner_id'] = $owner_id;

        return $this;
    }

    /**
     * Gets user_id
     *
     * @return int|null
     */
    public function getUserId()
    {
        return $this->container['user_id'];
    }

    /**
     * Sets user_id
     *
     * @param int|null $user_id The ID of the user related to the Webhook
     *
     * @return self
     */
    public function setUserId($user_id): self
    {
        $this->container['user_id'] = $user_id;

        return $this;
    }

    /**
     * Gets event_action
     *
     * @return string|null
     */
    public function getEventAction()
    {
        return $this->container['event_action'];
    }

    /**
     * Sets event_action
     *
     * @param string|null $event_action The Webhook action
     *
     * @return self
     */
    public function setEventAction($event_action): self
    {
        $this->container['event_action'] = $event_action;

        return $this;
    }

    /**
     * Gets event_object
     *
     * @return string|null
     */
    public function getEventObject()
    {
        return $this->container['event_object'];
    }

    /**
     * Sets event_object
     *
     * @param string|null $event_object The Webhook object
     *
     * @return self
     */
    public function setEventObject($event_object): self
    {
        $this->container['event_object'] = $event_object;

        return $this;
    }

    /**
     * Gets subscription_url
     *
     * @return string|null
     */
    public function getSubscriptionUrl()
    {
        return $this->container['subscription_url'];
    }

    /**
     * Sets subscription_url
     *
     * @param string|null $subscription_url The subscription URL of the Webhook
     *
     * @return self
     */
    public function setSubscriptionUrl($subscription_url): self
    {
        $this->container['subscription_url'] = $subscription_url;

        return $this;
    }

    /**
     * Gets is_active
     *
     * @return \Pipedrive\Model\NumberBooleanDefault1|null
     */
    public function getIsActive()
    {
        return $this->container['is_active'];
    }

    /**
     * Sets is_active
     *
     * @param \Pipedrive\Model\NumberBooleanDefault1|null $is_active The Webhook's status
     *
     * @return self
     */
    public function setIsActive($is_active): self
    {
        $this->container['is_active'] = $is_active;

        return $this;
    }

    /**
     * Gets add_time
     *
     * @return \DateTime|null
     */
    public function getAddTime()
    {
        return $this->container['add_time'];
    }

    /**
     * Sets add_time
     *
     * @param \DateTime|null $add_time The date when the Webhook was added
     *
     * @return self
     */
    public function setAddTime($add_time): self
    {
        $this->container['add_time'] = $add_time;

        return $this;
    }

    /**
     * Gets remove_time
     *
     * @return \DateTime|null
     */
    public function getRemoveTime()
    {
        return $this->container['remove_time'];
    }

    /**
     * Sets remove_time
     *
     * @param \DateTime|null $remove_time The date when the Webhook was removed (if removed)
     *
     * @return self
     */
    public function setRemoveTime($remove_time): self
    {
        $this->container['remove_time'] = $remove_time;

        return $this;
    }

    /**
     * Gets type
     *
     * @return string|null
     */
    public function getType()
    {
        return $this->container['type'];
    }

    /**
     * Sets type
     *
     * @param string|null $type The type of the Webhook
     *
     * @return self
     */
    public function setType($type): self
    {
        $allowedValues = $this->getTypeAllowableValues();
        if (!is_null($type) && !in_array($type, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'type', must be one of '%s'",
                    $type,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['type'] = $type;

        return $this;
    }

    /**
     * Gets http_auth_user
     *
     * @return string|null
     */
    public function getHttpAuthUser()
    {
        return $this->container['http_auth_user'];
    }

    /**
     * Sets http_auth_user
     *
     * @param string|null $http_auth_user The username of the `subscription_url` of the Webhook
     *
     * @return self
     */
    public function setHttpAuthUser($http_auth_user): self
    {
        $this->container['http_auth_user'] = $http_auth_user;

        return $this;
    }

    /**
     * Gets http_auth_password
     *
     * @return string|null
     */
    public function getHttpAuthPassword()
    {
        return $this->container['http_auth_password'];
    }

    /**
     * Sets http_auth_password
     *
     * @param string|null $http_auth_password The password of the `subscription_url` of the Webhook
     *
     * @return self
     */
    public function setHttpAuthPassword($http_auth_password): self
    {
        $this->container['http_auth_password'] = $http_auth_password;

        return $this;
    }

    /**
     * Gets additional_data
     *
     * @return object|null
     */
    public function getAdditionalData()
    {
        return $this->container['additional_data'];
    }

    /**
     * Sets additional_data
     *
     * @param object|null $additional_data Any additional data related to the Webhook
     *
     * @return self
     */
    public function setAdditionalData($additional_data): self
    {
        $this->container['additional_data'] = $additional_data;

        return $this;
    }

    /**
     * Gets remove_reason
     *
     * @return string|null
     */
    public function getRemoveReason()
    {
        return $this->container['remove_reason'];
    }

    /**
     * Sets remove_reason
     *
     * @param string|null $remove_reason The removal reason of the Webhook (if removed)
     *
     * @return self
     */
    public function setRemoveReason($remove_reason): self
    {
        $this->container['remove_reason'] = $remove_reason;

        return $this;
    }

    /**
     * Gets last_delivery_time
     *
     * @return \DateTime|null
     */
    public function getLastDeliveryTime()
    {
        return $this->container['last_delivery_time'];
    }

    /**
     * Sets last_delivery_time
     *
     * @param \DateTime|null $last_delivery_time The last delivery time of the Webhook
     *
     * @return self
     */
    public function setLastDeliveryTime($last_delivery_time): self
    {
        $this->container['last_delivery_time'] = $last_delivery_time;

        return $this;
    }

    /**
     * Gets last_http_status
     *
     * @return int|null
     */
    public function getLastHttpStatus()
    {
        return $this->container['last_http_status'];
    }

    /**
     * Sets last_http_status
     *
     * @param int|null $last_http_status The last delivery HTTP status of the Webhook
     *
     * @return self
     */
    public function setLastHttpStatus($last_http_status): self
    {
        $this->container['last_http_status'] = $last_http_status;

        return $this;
    }

    /**
     * Gets admin_id
     *
     * @return int|null
     */
    public function getAdminId()
    {
        return $this->container['admin_id'];
    }

    /**
     * Sets admin_id
     *
     * @param int|null $admin_id The ID of the admin of the Webhook
     *
     * @return self
     */
    public function setAdminId($admin_id): self
    {
        $this->container['admin_id'] = $admin_id;

        return $this;
    }
    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param integer $offset Offset
     *
     * @return boolean
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param integer $offset Offset
     *
     * @return mixed
     */
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param int|null $offset Offset
     * @param mixed    $value  Value to be set
     *
     * @return void
     */
    public function offsetSet($offset, $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param integer $offset Offset
     *
     * @return void
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed Returns data which can be serialized by json_encode(), which is a value
     * of any type other than a resource.
     */
    public function jsonSerialize(): mixed
    {
       return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets the string presentation of the object
     *
     * @throws JsonException
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR
        );
    }

    /**
     * Gets a header-safe presentation of the object
     *
     * @throws JsonException
     * @return string
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this), JSON_THROW_ON_ERROR);
    }
}


