# encoding: utf-8
# Code generated by Microsoft (R) AutoRest Code Generator 0.17.0.0
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.

require_relative '../arm/module_definition'
require_relative './module_definition'

module Azure::ARM::Network
    #
    # Model object.
    #
    class SubnetProperties < Azure::ARM::TypeBase

      # @return [String]
      attr_accessor :address_prefix

      # @return [Id]
      attr_accessor :network_security_group

      # @return [Id]
      attr_accessor :route_table

      #
      # Validate the object. Throws ValidationError if validation fails.
      #
      def validate
        fail ArgumentError, 'property address_prefix is nil' if @address_prefix.nil?
        @network_security_group.validate unless @network_security_group.nil?
        @route_table.validate unless @route_table.nil?
      end

      #
      # Serializes given Model object into Ruby Hash.
      # @param object Model object to serialize.
      # @return [Hash] Serialized object in form of Ruby Hash.
      #
      def self.serialize_object(output_object, object)
        Azure::ARM::TypeBase.serialize_object(output_object, object)
        object.validate

        serialized_property = object.address_prefix
        output_object[:addressPrefix] = serialized_property unless serialized_property.nil?

        serialized_property = object.network_security_group
        unless serialized_property.nil?
          serialized_property = serialized_property.to_h
        end
        output_object[:networkSecurityGroup] = serialized_property unless serialized_property.nil?

        serialized_property = object.route_table
        unless serialized_property.nil?
          serialized_property = serialized_property.to_h
        end
        output_object[:routeTable] = serialized_property unless serialized_property.nil?

        output_object
      end

      def to_h
        hash = {}
        SubnetProperties.serialize_object(hash,self)
        hash
      end

      def self.ds_properties
        result = Array.new 
        result.push :address_prefix
        result.push :network_security_group
        result.push :route_table
        result
      end

      #
      # Deserializes given Ruby Hash into Model object.
      # @param object [Hash] Ruby Hash object to deserialize.
      # @return [SubnetProperties] Deserialized object.
      #
      def self.deserialize_object(output_object, object)
        return if object.nil?
        conf = Configurator.new
        conf.parent = output_object

        if object.key?(:address_prefix)
          conf.address_prefix object[:address_prefix]
          object.delete :address_prefix
        end

        if object.key?(:network_security_group)
          conf.network_security_group object[:network_security_group]
          object.delete :network_security_group
        end

        if object.key?(:route_table)
          conf.route_table object[:route_table]
          object.delete :route_table
        end

        output_object
      end

      def get_name_template
        'sp'
        end

      def initialize(parent, init)
        super(parent)
        if init.is_a? Hash
          SubnetProperties.deserialize_object self, init.clone
        end
      end

      # Configuration code
      class Configurator < Azure::ARM::ResourceConfigurator
        attr_accessor :parent
        # @param address_prefix
        #        String
        def address_prefix(props)
          if props.is_a? String or props.is_a? Azure::ARM::Expression
            @parent.address_prefix = props
            return
          end
          @parent.address_prefix
        end
        # @param network_security_group
        #        Id
        def network_security_group(props)
          if @parent.network_security_group.nil? and props.is_a? Id
            @parent.network_security_group = props
            @parent.network_security_group.parent = @parent
            @parent.network_security_group._rsrcpath = 'networkSecurityGroup'
          end
          if @parent.network_security_group.nil? and (props.is_a? Hash) and (Azure::ARM::TypeBase.matches_type props, Id)
            @parent.network_security_group = Id.new(@parent, props)
            @parent.network_security_group._rsrcpath = 'networkSecurityGroup'
          end
          if @parent.network_security_group.nil? and (props.respond_to? :to_rsrcid)
            @parent.network_security_group = Id.new(@parent, id: props.to_rsrcid.to_s)
            if props.is_a? Azure::ARM::TypeBase and !props.containing_resource.nil?
              @parent.containing_resource.add_dependency props.containing_resource
            end
          end
          @parent.network_security_group
        end
        # @param route_table
        #        Id
        def route_table(props)
          if @parent.route_table.nil? and props.is_a? Id
            @parent.route_table = props
            @parent.route_table.parent = @parent
            @parent.route_table._rsrcpath = 'routeTable'
          end
          if @parent.route_table.nil? and (props.is_a? Hash) and (Azure::ARM::TypeBase.matches_type props, Id)
            @parent.route_table = Id.new(@parent, props)
            @parent.route_table._rsrcpath = 'routeTable'
          end
          if @parent.route_table.nil? and (props.respond_to? :to_rsrcid)
            @parent.route_table = Id.new(@parent, id: props.to_rsrcid.to_s)
            if props.is_a? Azure::ARM::TypeBase and !props.containing_resource.nil?
              @parent.containing_resource.add_dependency props.containing_resource
            end
          end
          @parent.route_table
        end
        def create(init=nil,&block)
          @parent = SubnetProperties.new nil, init
          self.instance_exec(@parent,&block) if block
          @parent
        end
      end
      def configure(&block)
        conf = Configurator.new
        conf.parent = self
        conf.instance_exec(self,&block) if block
        self
      end
    end
end
