# 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::Compute
    #
    # Model object.
    #
    class DataDisk < Azure::ARM::TypeBase

      # @return [String]
      attr_accessor :name

      # @return [String]
      attr_accessor :disk_size_gb

      # @return [Float]
      attr_accessor :lun

      # @return [VhdUri]
      attr_accessor :vhd

      # @return [String]
      attr_accessor :caching

      # @return
      attr_accessor :create_option

      #
      # Validate the object. Throws ValidationError if validation fails.
      #
      def validate
        fail ArgumentError, 'property name is nil' if @name.nil?
        fail ArgumentError, 'property lun is nil' if @lun.nil?
        fail ArgumentError, 'property vhd is nil' if @vhd.nil?
        fail ArgumentError, 'property create_option is nil' if @create_option.nil?
        @vhd.validate unless @vhd.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.name
        output_object[:name] = serialized_property unless serialized_property.nil?

        serialized_property = object.lun
        output_object[:lun] = serialized_property unless serialized_property.nil?

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

        serialized_property = object.create_option
        if serialized_property.is_a? Azure::ARM::Expression
          unless serialized_property.nil?
            serialized_property = serialized_property.to_s
          end
        end
        output_object[:createOption] = serialized_property unless serialized_property.nil?

        serialized_property = object.disk_size_gb
        output_object[:diskSizeGB] = serialized_property unless serialized_property.nil?

        serialized_property = object.caching
        output_object[:caching] = serialized_property unless serialized_property.nil?

        output_object
      end

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

      def self.ds_properties
        result = Array.new 
        result.push :disk_size_gb
        result.push :lun
        result.push :vhd
        result.push :caching
        result.push :create_option
        result
      end

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

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

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

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

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

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

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

        output_object
      end

      def get_name_template
        'dd'
        end

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

      # Configuration code
      class Configurator < Azure::ARM::ResourceConfigurator
        attr_accessor :parent
        # @param name
        #        String
        def name(props)
          if props.is_a? String or props.is_a? Azure::ARM::Expression
            @parent.name = props
            return
          end
          @parent.name
        end
        # @param disk_size_gb
        #        String
        def disk_size_gb(props)
          if props.is_a? String or props.is_a? Azure::ARM::Expression
            @parent.disk_size_gb = props
            return
          end
          @parent.disk_size_gb
        end
        # @param lun
        #        Float
        def lun(props)
          if props.is_a? Float or props.is_a? Azure::ARM::Expression
            @parent.lun = props
            return
          end
          @parent.lun
        end
        # @param vhd
        #        VhdUri
        def vhd(props)
          if @parent.vhd.nil? and props.is_a? VhdUri
            @parent.vhd = props
            @parent.vhd.parent = @parent
            @parent.vhd._rsrcpath = 'vhd'
          end
          if @parent.vhd.nil? and (props.is_a? Hash) and (Azure::ARM::TypeBase.matches_type props, VhdUri)
            @parent.vhd = VhdUri.new(@parent, props)
            @parent.vhd._rsrcpath = 'vhd'
          end
          @parent.vhd
        end
        # @param caching
        #        String
        def caching(props)
          if props.is_a? String or props.is_a? Azure::ARM::Expression
            @parent.caching = props
            return
          end
          @parent.caching
        end
        # @param create_option
        #        A string, one of 'FromImage','Empty','Attach'
        #        Expression
        def create_option(props)
          if props.is_a? String
            fail ArgumentError, "#{props} is an invalid value for @parent.create_option" unless ['FromImage','Empty','Attach'].index(props)
            @parent.create_option = props
            return
          end
          if @parent.create_option.nil? and props.is_a? Azure::ARM::Expression
            @parent.create_option = props
          end
          @parent.create_option
        end
        def create(init=nil,&block)
          @parent = DataDisk.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
