# pagarme_core_api
#
# This file was automatically generated by APIMATIC v2.0
# ( https://apimatic.io ).

module PagarmeCoreApi
  # Request for creating an order
  class CreateOrderRequest < BaseModel
    # Items
    # @return [List of CreateOrderItemRequest]
    attr_accessor :items

    # Customer
    # @return [CreateCustomerRequest]
    attr_accessor :customer

    # Payment data
    # @return [List of CreatePaymentRequest]
    attr_accessor :payments

    # The order code
    # @return [String]
    attr_accessor :code

    # The customer id
    # @return [String]
    attr_accessor :customer_id

    # Shipping data
    # @return [CreateShippingRequest]
    attr_accessor :shipping

    # Metadata
    # @return [Array<String, String>]
    attr_accessor :metadata

    # Defines whether the order will go through anti-fraud
    # @return [Boolean]
    attr_accessor :antifraud_enabled

    # Ip address
    # @return [String]
    attr_accessor :ip

    # Session id
    # @return [String]
    attr_accessor :session_id

    # Request's location
    # @return [CreateLocationRequest]
    attr_accessor :location

    # Device's informations
    # @return [CreateDeviceRequest]
    attr_accessor :device

    # Device's informations
    # @return [Boolean]
    attr_accessor :closed

    # Currency
    # @return [String]
    attr_accessor :currency

    # Currency
    # @return [CreateAntifraudRequest]
    attr_accessor :antifraud

    # SubMerchant
    # @return [CreateSubMerchantRequest]
    attr_accessor :submerchant

    # A mapping from model property names to API property names.
    def self.names
      @_hash = {} if @_hash.nil?
      @_hash['items'] = 'items'
      @_hash['customer'] = 'customer'
      @_hash['payments'] = 'payments'
      @_hash['code'] = 'code'
      @_hash['customer_id'] = 'customer_id'
      @_hash['shipping'] = 'shipping'
      @_hash['metadata'] = 'metadata'
      @_hash['antifraud_enabled'] = 'antifraud_enabled'
      @_hash['ip'] = 'ip'
      @_hash['session_id'] = 'session_id'
      @_hash['location'] = 'location'
      @_hash['device'] = 'device'
      @_hash['closed'] = 'closed'
      @_hash['currency'] = 'currency'
      @_hash['antifraud'] = 'antifraud'
      @_hash['submerchant'] = 'submerchant'
      @_hash
    end

    def initialize(items = nil,
                   customer = nil,
                   payments = nil,
                   code = nil,
                   customer_id = nil,
                   metadata = nil,
                   closed = true,
                   shipping = nil,
                   antifraud_enabled = nil,
                   ip = nil,
                   session_id = nil,
                   location = nil,
                   device = nil,
                   currency = nil,
                   antifraud = nil,
                   submerchant = nil)
      @items = items
      @customer = customer
      @payments = payments
      @code = code
      @customer_id = customer_id
      @shipping = shipping
      @metadata = metadata
      @antifraud_enabled = antifraud_enabled
      @ip = ip
      @session_id = session_id
      @location = location
      @device = device
      @closed = closed
      @currency = currency
      @antifraud = antifraud
      @submerchant = submerchant
    end

    # Creates an instance of the object from a hash.
    def self.from_hash(hash)
      return nil unless hash

      # Extract variables from the hash.
      # Parameter is an array, so we need to iterate through it
      items = nil
      unless hash['items'].nil?
        items = []
        hash['items'].each do |structure|
          items << (CreateOrderItemRequest.from_hash(structure) if structure)
        end
      end
      customer = CreateCustomerRequest.from_hash(hash['customer']) if
        hash['customer']
      # Parameter is an array, so we need to iterate through it
      payments = nil
      unless hash['payments'].nil?
        payments = []
        hash['payments'].each do |structure|
          payments << (CreatePaymentRequest.from_hash(structure) if structure)
        end
      end
      code = hash['code']
      customer_id = hash['customer_id']
      metadata = hash['metadata']
      closed = hash['closed'] ||= true
      shipping = CreateShippingRequest.from_hash(hash['shipping']) if
        hash['shipping']
      antifraud_enabled = hash['antifraud_enabled']
      ip = hash['ip']
      session_id = hash['session_id']
      location = CreateLocationRequest.from_hash(hash['location']) if
        hash['location']
      device = CreateDeviceRequest.from_hash(hash['device']) if hash['device']
      currency = hash['currency']
      antifraud = CreateAntifraudRequest.from_hash(hash['antifraud']) if
        hash['antifraud']
      submerchant = CreateSubMerchantRequest.from_hash(hash['submerchant']) if
        hash['submerchant']

      # Create object from extracted values.
      CreateOrderRequest.new(items,
                             customer,
                             payments,
                             code,
                             customer_id,
                             metadata,
                             closed,
                             shipping,
                             antifraud_enabled,
                             ip,
                             session_id,
                             location,
                             device,
                             currency,
                             antifraud,
                             submerchant)
    end
  end
end
