<?php
/**
 * GetPostSaleOptionsResponse
 *
 * PHP version 7.4
 *
 * @category Class
 * @package  Linnworks\Channel
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * linnworks_channel
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 1.0
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.11.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 Linnworks\Channel\Model;

use \ArrayAccess;
use \Linnworks\Channel\ObjectSerializer;

/**
 * GetPostSaleOptionsResponse Class Doc Comment
 *
 * @category Class
 * @package  Linnworks\Channel
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 * @implements \ArrayAccess<string, mixed>
 */
class GetPostSaleOptionsResponse implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'error' => 'string',
        'can_cancel' => 'bool',
        'can_cancel_order_lines' => 'bool',
        'can_cancel_order_lines_partially' => 'bool',
        'automatic_refund_on_cancel' => 'bool',
        'can_refund' => 'bool',
        'can_attach_refund_to_item' => 'bool',
        'can_attach_refund_to_service' => 'bool',
        'refund_shipping_types' => 'int',
        'can_refund_additionally' => 'bool',
        'can_return' => 'bool',
        'post_sale_reasons' => '\Linnworks\Channel\Model\PostSaleReasons[]'
    ];

    /**
      * 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 = [
        'error' => null,
        'can_cancel' => null,
        'can_cancel_order_lines' => null,
        'can_cancel_order_lines_partially' => null,
        'automatic_refund_on_cancel' => null,
        'can_refund' => null,
        'can_attach_refund_to_item' => null,
        'can_attach_refund_to_service' => null,
        'refund_shipping_types' => null,
        'can_refund_additionally' => null,
        'can_return' => null,
        'post_sale_reasons' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'error' => true,
        'can_cancel' => false,
        'can_cancel_order_lines' => false,
        'can_cancel_order_lines_partially' => false,
        'automatic_refund_on_cancel' => false,
        'can_refund' => false,
        'can_attach_refund_to_item' => false,
        'can_attach_refund_to_service' => false,
        'refund_shipping_types' => false,
        'can_refund_additionally' => false,
        'can_return' => false,
        'post_sale_reasons' => false
    ];

    /**
      * If a nullable field gets set to null, insert it here
      *
      * @var boolean[]
      */
    protected array $openAPINullablesSetToNull = [];

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

    /**
     * Array of property to format mappings. Used for (de)serialization
     *
     * @return array
     */
    public static function openAPIFormats()
    {
        return self::$openAPIFormats;
    }

    /**
     * Array of nullable properties
     *
     * @return array
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null
     *
     * @return boolean[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null
     *
     * @param boolean[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Checks if a property is nullable
     *
     * @param string $property
     * @return bool
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     *
     * @param string $property
     * @return bool
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name
     *
     * @var string[]
     */
    protected static $attributeMap = [
        'error' => 'Error',
        'can_cancel' => 'CanCancel',
        'can_cancel_order_lines' => 'CanCancelOrderLines',
        'can_cancel_order_lines_partially' => 'CanCancelOrderLinesPartially',
        'automatic_refund_on_cancel' => 'AutomaticRefundOnCancel',
        'can_refund' => 'CanRefund',
        'can_attach_refund_to_item' => 'CanAttachRefundToItem',
        'can_attach_refund_to_service' => 'CanAttachRefundToService',
        'refund_shipping_types' => 'RefundShippingTypes',
        'can_refund_additionally' => 'CanRefundAdditionally',
        'can_return' => 'CanReturn',
        'post_sale_reasons' => 'PostSaleReasons'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'error' => 'setError',
        'can_cancel' => 'setCanCancel',
        'can_cancel_order_lines' => 'setCanCancelOrderLines',
        'can_cancel_order_lines_partially' => 'setCanCancelOrderLinesPartially',
        'automatic_refund_on_cancel' => 'setAutomaticRefundOnCancel',
        'can_refund' => 'setCanRefund',
        'can_attach_refund_to_item' => 'setCanAttachRefundToItem',
        'can_attach_refund_to_service' => 'setCanAttachRefundToService',
        'refund_shipping_types' => 'setRefundShippingTypes',
        'can_refund_additionally' => 'setCanRefundAdditionally',
        'can_return' => 'setCanReturn',
        'post_sale_reasons' => 'setPostSaleReasons'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'error' => 'getError',
        'can_cancel' => 'getCanCancel',
        'can_cancel_order_lines' => 'getCanCancelOrderLines',
        'can_cancel_order_lines_partially' => 'getCanCancelOrderLinesPartially',
        'automatic_refund_on_cancel' => 'getAutomaticRefundOnCancel',
        'can_refund' => 'getCanRefund',
        'can_attach_refund_to_item' => 'getCanAttachRefundToItem',
        'can_attach_refund_to_service' => 'getCanAttachRefundToService',
        'refund_shipping_types' => 'getRefundShippingTypes',
        'can_refund_additionally' => 'getCanRefundAdditionally',
        'can_return' => 'getCanReturn',
        'post_sale_reasons' => 'getPostSaleReasons'
    ];

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

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @return array
     */
    public static function setters()
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @return array
     */
    public static function getters()
    {
        return self::$getters;
    }

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


    /**
     * Associative array for storing property values
     *
     * @var mixed[]
     */
    protected $container = [];

    /**
     * Constructor
     *
     * @param mixed[]|null $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('error', $data ?? [], null);
        $this->setIfExists('can_cancel', $data ?? [], null);
        $this->setIfExists('can_cancel_order_lines', $data ?? [], null);
        $this->setIfExists('can_cancel_order_lines_partially', $data ?? [], null);
        $this->setIfExists('automatic_refund_on_cancel', $data ?? [], null);
        $this->setIfExists('can_refund', $data ?? [], null);
        $this->setIfExists('can_attach_refund_to_item', $data ?? [], null);
        $this->setIfExists('can_attach_refund_to_service', $data ?? [], null);
        $this->setIfExists('refund_shipping_types', $data ?? [], null);
        $this->setIfExists('can_refund_additionally', $data ?? [], null);
        $this->setIfExists('can_return', $data ?? [], null);
        $this->setIfExists('post_sale_reasons', $data ?? [], null);
    }

    /**
    * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
    * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
    * $this->openAPINullablesSetToNull array
    *
    * @param string $variableName
    * @param array  $fields
    * @param mixed  $defaultValue
    */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalidProperties = [];

        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()
    {
        return count($this->listInvalidProperties()) === 0;
    }


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

    /**
     * Sets error
     *
     * @param string|null $error error
     *
     * @return self
     */
    public function setError($error)
    {
        if (is_null($error)) {
            array_push($this->openAPINullablesSetToNull, 'error');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('error', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['error'] = $error;

        return $this;
    }

    /**
     * Gets can_cancel
     *
     * @return bool|null
     */
    public function getCanCancel()
    {
        return $this->container['can_cancel'];
    }

    /**
     * Sets can_cancel
     *
     * @param bool|null $can_cancel can_cancel
     *
     * @return self
     */
    public function setCanCancel($can_cancel)
    {
        if (is_null($can_cancel)) {
            throw new \InvalidArgumentException('non-nullable can_cancel cannot be null');
        }
        $this->container['can_cancel'] = $can_cancel;

        return $this;
    }

    /**
     * Gets can_cancel_order_lines
     *
     * @return bool|null
     */
    public function getCanCancelOrderLines()
    {
        return $this->container['can_cancel_order_lines'];
    }

    /**
     * Sets can_cancel_order_lines
     *
     * @param bool|null $can_cancel_order_lines can_cancel_order_lines
     *
     * @return self
     */
    public function setCanCancelOrderLines($can_cancel_order_lines)
    {
        if (is_null($can_cancel_order_lines)) {
            throw new \InvalidArgumentException('non-nullable can_cancel_order_lines cannot be null');
        }
        $this->container['can_cancel_order_lines'] = $can_cancel_order_lines;

        return $this;
    }

    /**
     * Gets can_cancel_order_lines_partially
     *
     * @return bool|null
     */
    public function getCanCancelOrderLinesPartially()
    {
        return $this->container['can_cancel_order_lines_partially'];
    }

    /**
     * Sets can_cancel_order_lines_partially
     *
     * @param bool|null $can_cancel_order_lines_partially can_cancel_order_lines_partially
     *
     * @return self
     */
    public function setCanCancelOrderLinesPartially($can_cancel_order_lines_partially)
    {
        if (is_null($can_cancel_order_lines_partially)) {
            throw new \InvalidArgumentException('non-nullable can_cancel_order_lines_partially cannot be null');
        }
        $this->container['can_cancel_order_lines_partially'] = $can_cancel_order_lines_partially;

        return $this;
    }

    /**
     * Gets automatic_refund_on_cancel
     *
     * @return bool|null
     */
    public function getAutomaticRefundOnCancel()
    {
        return $this->container['automatic_refund_on_cancel'];
    }

    /**
     * Sets automatic_refund_on_cancel
     *
     * @param bool|null $automatic_refund_on_cancel automatic_refund_on_cancel
     *
     * @return self
     */
    public function setAutomaticRefundOnCancel($automatic_refund_on_cancel)
    {
        if (is_null($automatic_refund_on_cancel)) {
            throw new \InvalidArgumentException('non-nullable automatic_refund_on_cancel cannot be null');
        }
        $this->container['automatic_refund_on_cancel'] = $automatic_refund_on_cancel;

        return $this;
    }

    /**
     * Gets can_refund
     *
     * @return bool|null
     */
    public function getCanRefund()
    {
        return $this->container['can_refund'];
    }

    /**
     * Sets can_refund
     *
     * @param bool|null $can_refund can_refund
     *
     * @return self
     */
    public function setCanRefund($can_refund)
    {
        if (is_null($can_refund)) {
            throw new \InvalidArgumentException('non-nullable can_refund cannot be null');
        }
        $this->container['can_refund'] = $can_refund;

        return $this;
    }

    /**
     * Gets can_attach_refund_to_item
     *
     * @return bool|null
     */
    public function getCanAttachRefundToItem()
    {
        return $this->container['can_attach_refund_to_item'];
    }

    /**
     * Sets can_attach_refund_to_item
     *
     * @param bool|null $can_attach_refund_to_item can_attach_refund_to_item
     *
     * @return self
     */
    public function setCanAttachRefundToItem($can_attach_refund_to_item)
    {
        if (is_null($can_attach_refund_to_item)) {
            throw new \InvalidArgumentException('non-nullable can_attach_refund_to_item cannot be null');
        }
        $this->container['can_attach_refund_to_item'] = $can_attach_refund_to_item;

        return $this;
    }

    /**
     * Gets can_attach_refund_to_service
     *
     * @return bool|null
     */
    public function getCanAttachRefundToService()
    {
        return $this->container['can_attach_refund_to_service'];
    }

    /**
     * Sets can_attach_refund_to_service
     *
     * @param bool|null $can_attach_refund_to_service can_attach_refund_to_service
     *
     * @return self
     */
    public function setCanAttachRefundToService($can_attach_refund_to_service)
    {
        if (is_null($can_attach_refund_to_service)) {
            throw new \InvalidArgumentException('non-nullable can_attach_refund_to_service cannot be null');
        }
        $this->container['can_attach_refund_to_service'] = $can_attach_refund_to_service;

        return $this;
    }

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

    /**
     * Sets refund_shipping_types
     *
     * @param int|null $refund_shipping_types refund_shipping_types
     *
     * @return self
     */
    public function setRefundShippingTypes($refund_shipping_types)
    {
        if (is_null($refund_shipping_types)) {
            throw new \InvalidArgumentException('non-nullable refund_shipping_types cannot be null');
        }
        $this->container['refund_shipping_types'] = $refund_shipping_types;

        return $this;
    }

    /**
     * Gets can_refund_additionally
     *
     * @return bool|null
     */
    public function getCanRefundAdditionally()
    {
        return $this->container['can_refund_additionally'];
    }

    /**
     * Sets can_refund_additionally
     *
     * @param bool|null $can_refund_additionally can_refund_additionally
     *
     * @return self
     */
    public function setCanRefundAdditionally($can_refund_additionally)
    {
        if (is_null($can_refund_additionally)) {
            throw new \InvalidArgumentException('non-nullable can_refund_additionally cannot be null');
        }
        $this->container['can_refund_additionally'] = $can_refund_additionally;

        return $this;
    }

    /**
     * Gets can_return
     *
     * @return bool|null
     */
    public function getCanReturn()
    {
        return $this->container['can_return'];
    }

    /**
     * Sets can_return
     *
     * @param bool|null $can_return can_return
     *
     * @return self
     */
    public function setCanReturn($can_return)
    {
        if (is_null($can_return)) {
            throw new \InvalidArgumentException('non-nullable can_return cannot be null');
        }
        $this->container['can_return'] = $can_return;

        return $this;
    }

    /**
     * Gets post_sale_reasons
     *
     * @return \Linnworks\Channel\Model\PostSaleReasons[]|null
     */
    public function getPostSaleReasons()
    {
        return $this->container['post_sale_reasons'];
    }

    /**
     * Sets post_sale_reasons
     *
     * @param \Linnworks\Channel\Model\PostSaleReasons[]|null $post_sale_reasons post_sale_reasons
     *
     * @return self
     */
    public function setPostSaleReasons($post_sale_reasons)
    {
        if (is_null($post_sale_reasons)) {
            throw new \InvalidArgumentException('non-nullable post_sale_reasons cannot be null');
        }
        $this->container['post_sale_reasons'] = $post_sale_reasons;

        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|null
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset)
    {
        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.
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize()
    {
       return ObjectSerializer::sanitizeForSerialization($this);
    }

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

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


