# 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/organizationapi_labels'
require 'google/apigee/property/organizationapi_meta_data'

# A provider to manage Apigee resources.
class ApigeeOrganizationApi < GcpResourceBase
  name 'google_apigee_organization_api'
  desc 'OrganizationApi'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :revision
  attr_reader :latest_revision_id
  attr_reader :meta_data
  attr_reader :api_proxy_type
  attr_reader :read_only
  attr_reader :labels
  attr_reader :name

  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
    @revision = @fetched['revision']
    @latest_revision_id = @fetched['latestRevisionId']
    @meta_data = GoogleInSpec::Apigee::Property::OrganizationApiMetaData.new(@fetched['metaData'], to_s)
    @api_proxy_type = @fetched['apiProxyType']
    @read_only = @fetched['readOnly']
    @labels = GoogleInSpec::Apigee::Property::OrganizationApiLabels.new(@fetched['labels'], to_s)
    @name = @fetched['name']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{parent}}/apis/{{name}}'
  end
end
