<?php

/**
 * Adyen Checkout API
 *
 * The version of the OpenAPI document: 71
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 6.0.1
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


namespace Adyen\Model\Checkout;

use ArrayAccess;
use Adyen\Model\Checkout\ObjectSerializer;

/**
 * Leg Class Doc Comment
 *
 * @package  Adyen
 * @implements ArrayAccess<string, mixed>
 */
class Leg implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'carrierCode' => 'string',
        'classOfTravel' => 'string',
        'dateOfTravel' => '\DateTime',
        'departureAirportCode' => 'string',
        'departureTax' => 'int',
        'destinationAirportCode' => 'string',
        'fareBasisCode' => 'string',
        'flightNumber' => 'string',
        'stopOverCode' => 'string'
    ];

    /**
      * 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 = [
        'carrierCode' => null,
        'classOfTravel' => null,
        'dateOfTravel' => 'date-time',
        'departureAirportCode' => null,
        'departureTax' => 'int64',
        'destinationAirportCode' => null,
        'fareBasisCode' => null,
        'flightNumber' => null,
        'stopOverCode' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static $openAPINullables = [
        'carrierCode' => false,
        'classOfTravel' => false,
        'dateOfTravel' => false,
        'departureAirportCode' => false,
        'departureTax' => false,
        'destinationAirportCode' => false,
        'fareBasisCode' => false,
        'flightNumber' => false,
        'stopOverCode' => false
    ];

    /**
      * If a nullable field gets set to null, insert it here
      *
      * @var boolean[]
      */
    protected $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 = [
        'carrierCode' => 'carrierCode',
        'classOfTravel' => 'classOfTravel',
        'dateOfTravel' => 'dateOfTravel',
        'departureAirportCode' => 'departureAirportCode',
        'departureTax' => 'departureTax',
        'destinationAirportCode' => 'destinationAirportCode',
        'fareBasisCode' => 'fareBasisCode',
        'flightNumber' => 'flightNumber',
        'stopOverCode' => 'stopOverCode'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'carrierCode' => 'setCarrierCode',
        'classOfTravel' => 'setClassOfTravel',
        'dateOfTravel' => 'setDateOfTravel',
        'departureAirportCode' => 'setDepartureAirportCode',
        'departureTax' => 'setDepartureTax',
        'destinationAirportCode' => 'setDestinationAirportCode',
        'fareBasisCode' => 'setFareBasisCode',
        'flightNumber' => 'setFlightNumber',
        'stopOverCode' => 'setStopOverCode'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'carrierCode' => 'getCarrierCode',
        'classOfTravel' => 'getClassOfTravel',
        'dateOfTravel' => 'getDateOfTravel',
        'departureAirportCode' => 'getDepartureAirportCode',
        'departureTax' => 'getDepartureTax',
        'destinationAirportCode' => 'getDestinationAirportCode',
        'fareBasisCode' => 'getFareBasisCode',
        'flightNumber' => 'getFlightNumber',
        'stopOverCode' => 'getStopOverCode'
    ];

    /**
     * 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[] $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('carrierCode', $data ?? [], null);
        $this->setIfExists('classOfTravel', $data ?? [], null);
        $this->setIfExists('dateOfTravel', $data ?? [], null);
        $this->setIfExists('departureAirportCode', $data ?? [], null);
        $this->setIfExists('departureTax', $data ?? [], null);
        $this->setIfExists('destinationAirportCode', $data ?? [], null);
        $this->setIfExists('fareBasisCode', $data ?? [], null);
        $this->setIfExists('flightNumber', $data ?? [], null);
        $this->setIfExists('stopOverCode', $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 carrierCode
     *
     * @return string|null
     */
    public function getCarrierCode()
    {
        return $this->container['carrierCode'];
    }

    /**
     * Sets carrierCode
     *
     * @param string|null $carrierCode The [IATA](https://www.iata.org/services/pages/codes.aspx) 2-letter accounting code (PAX) that identifies the carrier. This field is required if the airline data includes leg details. * Example: KLM = KL * minLength: 2 characters * maxLength: 2 characters * Must not start with a space or be all spaces. * Must not be all zeros.
     *
     * @return self
     */
    public function setCarrierCode($carrierCode)
    {
        $this->container['carrierCode'] = $carrierCode;

        return $this;
    }

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

    /**
     * Sets classOfTravel
     *
     * @param string|null $classOfTravel A one-letter travel class identifier.  The following are common:  * F: first class * J: business class * Y: economy class * W: premium economy  * Encoding: ASCII * minLength: 1 character * maxLength: 1 character * Must not start with a space or be all spaces. * Must not be all zeros.
     *
     * @return self
     */
    public function setClassOfTravel($classOfTravel)
    {
        $this->container['classOfTravel'] = $classOfTravel;

        return $this;
    }

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

    /**
     * Sets dateOfTravel
     *
     * @param \DateTime|null $dateOfTravel Date and time of travel in format `yyyy-MM-ddTHH:mm`. * Use local time of departure airport. * minLength: 16 characters * maxLength: 16 characters
     *
     * @return self
     */
    public function setDateOfTravel($dateOfTravel)
    {
        $this->container['dateOfTravel'] = $dateOfTravel;

        return $this;
    }

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

    /**
     * Sets departureAirportCode
     *
     * @param string|null $departureAirportCode The [IATA](https://www.iata.org/services/pages/codes.aspx) three-letter airport code of the departure airport. This field is required if the airline data includes leg details.  * Encoding: ASCII * Example: Amsterdam = AMS * minLength: 3 characters * maxLength: 3 characters * Must not start with a space or be all spaces. * Must not be all zeros.
     *
     * @return self
     */
    public function setDepartureAirportCode($departureAirportCode)
    {
        $this->container['departureAirportCode'] = $departureAirportCode;

        return $this;
    }

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

    /**
     * Sets departureTax
     *
     * @param int|null $departureTax The amount of [departure tax](https://en.wikipedia.org/wiki/Departure_tax) charged, in [minor units](https://docs.adyen.com/development-resources/currency-codes). * Encoding: Numeric * minLength: 1 * maxLength: 11 * Must not be all zeros.
     *
     * @return self
     */
    public function setDepartureTax($departureTax)
    {
        $this->container['departureTax'] = $departureTax;

        return $this;
    }

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

    /**
     * Sets destinationAirportCode
     *
     * @param string|null $destinationAirportCode The [IATA](https://www.iata.org/services/pages/codes.aspx) 3-letter airport code of the destination airport. This field is required if the airline data includes leg details. * Example: Amsterdam = AMS * Encoding: ASCII * minLength: 3 characters * maxLength: 3 characters * Must not start with a space or be all spaces. * Must not be all zeros.
     *
     * @return self
     */
    public function setDestinationAirportCode($destinationAirportCode)
    {
        $this->container['destinationAirportCode'] = $destinationAirportCode;

        return $this;
    }

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

    /**
     * Sets fareBasisCode
     *
     * @param string|null $fareBasisCode The [fare basis code](https://en.wikipedia.org/wiki/Fare_basis_code), alphanumeric. * minLength: 1 character * maxLength: 15 characters * Must not start with a space or be all spaces. * Must not be all zeros.
     *
     * @return self
     */
    public function setFareBasisCode($fareBasisCode)
    {
        $this->container['fareBasisCode'] = $fareBasisCode;

        return $this;
    }

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

    /**
     * Sets flightNumber
     *
     * @param string|null $flightNumber The flight identifier. * minLength: 1 character * maxLength: 5 characters * Must not start with a space or be all spaces. * Must not be all zeros.
     *
     * @return self
     */
    public function setFlightNumber($flightNumber)
    {
        $this->container['flightNumber'] = $flightNumber;

        return $this;
    }

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

    /**
     * Sets stopOverCode
     *
     * @param string|null $stopOverCode A one-letter code that indicates whether the passenger is entitled to make a stopover. Can be a space, O if the passenger is entitled to make a stopover, or X if they are not. * Encoding: ASCII * minLength: 1 character * maxLength: 1 character
     *
     * @return self
     */
    public function setStopOverCode($stopOverCode)
    {
        $this->container['stopOverCode'] = $stopOverCode;

        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);
    }

    public function toArray(): array
    {
        $array = [];
        foreach (self::$openAPITypes as $propertyName => $propertyType) {
            $propertyValue = $this[$propertyName];
            if ($propertyValue !== null) {
                // Check if the property value is an object and has a toArray() method
                if (is_object($propertyValue) && method_exists($propertyValue, 'toArray')) {
                    $array[$propertyName] = $propertyValue->toArray();
                // Check if it's type datetime
                } elseif ($propertyValue instanceof \DateTime) {
                    $array[$propertyName] = $propertyValue->format(DATE_ATOM);
                // If it's an array type we should check whether it contains objects and if so call toArray method
                } elseif (is_array($propertyValue)) {
                    $array[$propertyName] = array_map(function ($item) {
                        return $item instanceof ModelInterface ? $item->toArray() : $item;
                    }, $propertyValue);
                } else {
                    // Otherwise, directly assign the property value to the array
                    $array[$propertyName] = $propertyValue;
                }
            }
        }
        return $array;
    }

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