<?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;

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'agency' => '\Adyen\Model\Checkout\Agency',
        'boardingFee' => 'int',
        'code' => 'string',
        'computerizedReservationSystem' => 'string',
        'customerReferenceNumber' => 'string',
        'designatorCode' => 'string',
        'documentType' => 'string',
        'flightDate' => '\DateTime',
        'legs' => '\Adyen\Model\Checkout\Leg[]',
        'passengerName' => 'string',
        'passengers' => '\Adyen\Model\Checkout\Passenger[]',
        'ticket' => '\Adyen\Model\Checkout\Ticket',
        'travelAgency' => '\Adyen\Model\Checkout\TravelAgency'
    ];

    /**
      * 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 = [
        'agency' => null,
        'boardingFee' => 'int64',
        'code' => null,
        'computerizedReservationSystem' => null,
        'customerReferenceNumber' => null,
        'designatorCode' => null,
        'documentType' => null,
        'flightDate' => 'date-time',
        'legs' => null,
        'passengerName' => null,
        'passengers' => null,
        'ticket' => null,
        'travelAgency' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static $openAPINullables = [
        'agency' => false,
        'boardingFee' => false,
        'code' => false,
        'computerizedReservationSystem' => false,
        'customerReferenceNumber' => false,
        'designatorCode' => false,
        'documentType' => false,
        'flightDate' => false,
        'legs' => false,
        'passengerName' => false,
        'passengers' => false,
        'ticket' => false,
        'travelAgency' => 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 = [
        'agency' => 'agency',
        'boardingFee' => 'boardingFee',
        'code' => 'code',
        'computerizedReservationSystem' => 'computerizedReservationSystem',
        'customerReferenceNumber' => 'customerReferenceNumber',
        'designatorCode' => 'designatorCode',
        'documentType' => 'documentType',
        'flightDate' => 'flightDate',
        'legs' => 'legs',
        'passengerName' => 'passengerName',
        'passengers' => 'passengers',
        'ticket' => 'ticket',
        'travelAgency' => 'travelAgency'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'agency' => 'setAgency',
        'boardingFee' => 'setBoardingFee',
        'code' => 'setCode',
        'computerizedReservationSystem' => 'setComputerizedReservationSystem',
        'customerReferenceNumber' => 'setCustomerReferenceNumber',
        'designatorCode' => 'setDesignatorCode',
        'documentType' => 'setDocumentType',
        'flightDate' => 'setFlightDate',
        'legs' => 'setLegs',
        'passengerName' => 'setPassengerName',
        'passengers' => 'setPassengers',
        'ticket' => 'setTicket',
        'travelAgency' => 'setTravelAgency'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'agency' => 'getAgency',
        'boardingFee' => 'getBoardingFee',
        'code' => 'getCode',
        'computerizedReservationSystem' => 'getComputerizedReservationSystem',
        'customerReferenceNumber' => 'getCustomerReferenceNumber',
        'designatorCode' => 'getDesignatorCode',
        'documentType' => 'getDocumentType',
        'flightDate' => 'getFlightDate',
        'legs' => 'getLegs',
        'passengerName' => 'getPassengerName',
        'passengers' => 'getPassengers',
        'ticket' => 'getTicket',
        'travelAgency' => 'getTravelAgency'
    ];

    /**
     * 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('agency', $data ?? [], null);
        $this->setIfExists('boardingFee', $data ?? [], null);
        $this->setIfExists('code', $data ?? [], null);
        $this->setIfExists('computerizedReservationSystem', $data ?? [], null);
        $this->setIfExists('customerReferenceNumber', $data ?? [], null);
        $this->setIfExists('designatorCode', $data ?? [], null);
        $this->setIfExists('documentType', $data ?? [], null);
        $this->setIfExists('flightDate', $data ?? [], null);
        $this->setIfExists('legs', $data ?? [], null);
        $this->setIfExists('passengerName', $data ?? [], null);
        $this->setIfExists('passengers', $data ?? [], null);
        $this->setIfExists('ticket', $data ?? [], null);
        $this->setIfExists('travelAgency', $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 = [];

        if ($this->container['passengerName'] === null) {
            $invalidProperties[] = "'passengerName' can't be null";
        }
        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 agency
     *
     * @return \Adyen\Model\Checkout\Agency|null
     */
    public function getAgency()
    {
        return $this->container['agency'];
    }

    /**
     * Sets agency
     *
     * @param \Adyen\Model\Checkout\Agency|null $agency agency
     *
     * @return self
     */
    public function setAgency($agency)
    {
        $this->container['agency'] = $agency;

        return $this;
    }

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

    /**
     * Sets boardingFee
     *
     * @param int|null $boardingFee The amount charged for boarding the plane, in [minor units](https://docs.adyen.com/development-resources/currency-codes). * Encoding: Numeric * minLength: 1 character * maxLength: 11 characters
     *
     * @return self
     */
    public function setBoardingFee($boardingFee)
    {
        $this->container['boardingFee'] = $boardingFee;

        return $this;
    }

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

    /**
     * Sets code
     *
     * @param string|null $code The [IATA](https://www.iata.org/services/pages/codes.aspx) 3-digit accounting code (PAX) that identifies the carrier. * Format: IATA 3-digit accounting code (PAX) * Example: KLM = 074 * 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 setCode($code)
    {
        $this->container['code'] = $code;

        return $this;
    }

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

    /**
     * Sets computerizedReservationSystem
     *
     * @param string|null $computerizedReservationSystem The [CRS](https://en.wikipedia.org/wiki/Computer_reservation_system) used to make the reservation and purchase the ticket. * Encoding: ASCII * minLength: 4 characters * maxLength: 4 characters
     *
     * @return self
     */
    public function setComputerizedReservationSystem($computerizedReservationSystem)
    {
        $this->container['computerizedReservationSystem'] = $computerizedReservationSystem;

        return $this;
    }

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

    /**
     * Sets customerReferenceNumber
     *
     * @param string|null $customerReferenceNumber The alphanumeric customer reference number. * Encoding: ASCII * maxLength: 20 characters * If you send more than 20 characters, the customer reference number is truncated * Must not start with a space or be all spaces.
     *
     * @return self
     */
    public function setCustomerReferenceNumber($customerReferenceNumber)
    {
        $this->container['customerReferenceNumber'] = $customerReferenceNumber;

        return $this;
    }

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

    /**
     * Sets designatorCode
     *
     * @param string|null $designatorCode The [IATA](https://www.iata.org/services/pages/codes.aspx) 2-letter accounting code (PAX) that identifies the carrier. * Encoding: ASCII * Example: KLM = KL * minLength: 2 characters * maxLength: 2 characters * Must not start with a space or be all spaces.
     *
     * @return self
     */
    public function setDesignatorCode($designatorCode)
    {
        $this->container['designatorCode'] = $designatorCode;

        return $this;
    }

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

    /**
     * Sets documentType
     *
     * @param string|null $documentType A code that identifies the type of item bought. The description of the code can appear on credit card statements. * Encoding: ASCII * Example: Passenger ticket = 01 * minLength: 2 characters * maxLength: 2 characters
     *
     * @return self
     */
    public function setDocumentType($documentType)
    {
        $this->container['documentType'] = $documentType;

        return $this;
    }

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

    /**
     * Sets flightDate
     *
     * @param \DateTime|null $flightDate The flight departure date. Time is optional. * Format for date only: `yyyy-MM-dd` * Format for date and time: `yyyy-MM-ddTHH:mm` * Use local time of departure airport. * minLength: 10 characters * maxLength: 16 characters
     *
     * @return self
     */
    public function setFlightDate($flightDate)
    {
        $this->container['flightDate'] = $flightDate;

        return $this;
    }

    /**
     * Gets legs
     *
     * @return \Adyen\Model\Checkout\Leg[]|null
     */
    public function getLegs()
    {
        return $this->container['legs'];
    }

    /**
     * Sets legs
     *
     * @param \Adyen\Model\Checkout\Leg[]|null $legs legs
     *
     * @return self
     */
    public function setLegs($legs)
    {
        $this->container['legs'] = $legs;

        return $this;
    }

    /**
     * Gets passengerName
     *
     * @return string
     */
    public function getPassengerName()
    {
        return $this->container['passengerName'];
    }

    /**
     * Sets passengerName
     *
     * @param string $passengerName The passenger's name, initials, and title. * Format: last name + first name or initials + title * Example: *FLYER / MARY MS* * minLength: 1 character * maxLength: 20 characters * If you send more than 20 characters, the name is truncated * Must not start with a space or be all spaces. * Must not be all zeros.
     *
     * @return self
     */
    public function setPassengerName($passengerName)
    {
        $this->container['passengerName'] = $passengerName;

        return $this;
    }

    /**
     * Gets passengers
     *
     * @return \Adyen\Model\Checkout\Passenger[]|null
     */
    public function getPassengers()
    {
        return $this->container['passengers'];
    }

    /**
     * Sets passengers
     *
     * @param \Adyen\Model\Checkout\Passenger[]|null $passengers passengers
     *
     * @return self
     */
    public function setPassengers($passengers)
    {
        $this->container['passengers'] = $passengers;

        return $this;
    }

    /**
     * Gets ticket
     *
     * @return \Adyen\Model\Checkout\Ticket|null
     */
    public function getTicket()
    {
        return $this->container['ticket'];
    }

    /**
     * Sets ticket
     *
     * @param \Adyen\Model\Checkout\Ticket|null $ticket ticket
     *
     * @return self
     */
    public function setTicket($ticket)
    {
        $this->container['ticket'] = $ticket;

        return $this;
    }

    /**
     * Gets travelAgency
     *
     * @return \Adyen\Model\Checkout\TravelAgency|null
     */
    public function getTravelAgency()
    {
        return $this->container['travelAgency'];
    }

    /**
     * Sets travelAgency
     *
     * @param \Adyen\Model\Checkout\TravelAgency|null $travelAgency travelAgency
     *
     * @return self
     */
    public function setTravelAgency($travelAgency)
    {
        $this->container['travelAgency'] = $travelAgency;

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