# 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/apigee/property/organization_addons_config'
require 'google/apigee/property/organization_addons_config_advanced_api_ops_config'
require 'google/apigee/property/organization_addons_config_analytics_config'
require 'google/apigee/property/organization_addons_config_api_security_config'
require 'google/apigee/property/organization_addons_config_connectors_platform_config'
require 'google/apigee/property/organization_addons_config_integration_config'
require 'google/apigee/property/organization_addons_config_monetization_config'
require 'google/apigee/property/organization_properties'
require 'google/apigee/property/organization_properties_property'

# A provider to manage Apigee resources.
class ApigeeOrganization < GcpResourceBase
  name 'google_apigee_organization'
  desc 'Organization'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :api_consumer_data_encryption_key_name
  attr_reader :runtime_database_encryption_key_name
  attr_reader :environments
  attr_reader :runtime_type
  attr_reader :type
  attr_reader :portal_disabled
  attr_reader :authorized_network
  attr_reader :project_id
  attr_reader :description
  attr_reader :ca_certificate
  attr_reader :subscription_type
  attr_reader :addons_config
  attr_reader :customer_name
  attr_reader :created_at
  attr_reader :last_modified_at
  attr_reader :subscription_plan
  attr_reader :properties
  attr_reader :state
  attr_reader :name
  attr_reader :disable_vpc_peering
  attr_reader :control_plane_encryption_key_name
  attr_reader :analytics_region
  attr_reader :api_consumer_data_location
  attr_reader :display_name
  attr_reader :apigee_project_id
  attr_reader :expires_at
  attr_reader :attributes
  attr_reader :billing_type

  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
    @api_consumer_data_encryption_key_name = @fetched['apiConsumerDataEncryptionKeyName']
    @runtime_database_encryption_key_name = @fetched['runtimeDatabaseEncryptionKeyName']
    @environments = @fetched['environments']
    @runtime_type = @fetched['runtimeType']
    @type = @fetched['type']
    @portal_disabled = @fetched['portalDisabled']
    @authorized_network = @fetched['authorizedNetwork']
    @project_id = @fetched['projectId']
    @description = @fetched['description']
    @ca_certificate = @fetched['caCertificate']
    @subscription_type = @fetched['subscriptionType']
    @addons_config = GoogleInSpec::Apigee::Property::OrganizationAddonsConfig.new(@fetched['addonsConfig'], to_s)
    @customer_name = @fetched['customerName']
    @created_at = @fetched['createdAt']
    @last_modified_at = @fetched['lastModifiedAt']
    @subscription_plan = @fetched['subscriptionPlan']
    @properties = GoogleInSpec::Apigee::Property::OrganizationProperties.new(@fetched['properties'], to_s)
    @state = @fetched['state']
    @name = @fetched['name']
    @disable_vpc_peering = @fetched['disableVpcPeering']
    @control_plane_encryption_key_name = @fetched['controlPlaneEncryptionKeyName']
    @analytics_region = @fetched['analyticsRegion']
    @api_consumer_data_location = @fetched['apiConsumerDataLocation']
    @display_name = @fetched['displayName']
    @apigee_project_id = @fetched['apigeeProjectId']
    @expires_at = @fetched['expiresAt']
    @attributes = @fetched['attributes']
    @billing_type = @fetched['billingType']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
