# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
#     ***     AUTO GENERATED CODE    ***    Type: MMv1     ***
#
# ----------------------------------------------------------------------------
#
#     This file is automatically generated by Magic Modules and manual
#     changes will be clobbered when the file is regenerated.
#
#     Please read more about how to change this file in README.md and
#     CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
require 'google/container/property/serverconfig_channels'

# A provider to manage Google Kubernetes Engine resources.
class ContainerServerConfig < GcpResourceBase
  name 'google_container_server_config'
  desc 'ServerConfig'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :default_cluster_version
  attr_reader :default_image_type
  attr_reader :valid_image_types
  attr_reader :valid_node_versions
  attr_reader :valid_master_versions
  attr_reader :channels
  attr_reader :location

  def initialize(params)
    super(params.merge({ use_http_transport: true }))
    @params = params
    @fetched = @connection.fetch(product_url(params[:beta]), resource_base_url, params, 'Get')
    parse unless @fetched.nil?
  end

  def parse
    @default_cluster_version = @fetched['defaultClusterVersion']
    @default_image_type = @fetched['defaultImageType']
    @valid_image_types = @fetched['validImageTypes']
    @valid_node_versions = @fetched['validNodeVersions']
    @valid_master_versions = @fetched['validMasterVersions']
    @channels = GoogleInSpec::Container::Property::ServerConfigChannelsArray.parse(@fetched['channels'], to_s)
    @location = @fetched['location']
  end

  def exists?
    !@fetched.nil?
  end

  def to_s
    "ServerConfig #{@params[:name]}"
  end

  private

  def product_url(_ = nil)
    'https://container.googleapis.com/v1/'
  end

  def resource_base_url
    'projects/{{project}}/locations/{{location}}/serverConfig/'
  end
end
