// Code generated by protoc-gen-a2config. DO NOT EDIT.
// source: config/es_sidecar/config_request.proto

package es_sidecar

import (
	shared "github.com/chef/automate/api/config/shared"
	a2conf "github.com/chef/automate/components/automate-grpc/protoc-gen-a2-config/api/a2conf"
	wrappers "github.com/golang/protobuf/ptypes/wrappers"
	wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
)

// ServiceName returns the name of the service this config belongs to
func (m *ConfigRequest) ServiceName() string {
	return "es-sidecar-service"
}

// BindPort sets the port tagged with the given name
func (m *ConfigRequest) BindPort(name string, value uint16) error {
	switch name {
	case "service":
		v0 := &m.V1
		if *v0 == nil {
			*v0 = &ConfigRequest_V1{}
		}
		v1 := &(*v0).Sys
		if *v1 == nil {
			*v1 = &ConfigRequest_V1_System{}
		}
		v2 := &(*v1).Service
		if *v2 == nil {
			*v2 = &ConfigRequest_V1_System_Service{}
		}
		v3 := &(*v2).Port
		*v3 = &wrappers.Int32Value{Value: int32(value)}
	default:
		return a2conf.ErrPortNotFound
	}
	return nil
}

// ListPorts lists all the ports exposed by the config
func (m *ConfigRequest) ListPorts() []a2conf.PortInfo {
	return []a2conf.PortInfo{a2conf.PortInfo{
		Default:  uint16(int32(10123)),
		Name:     "service",
		Protocol: "grpc",
	}}
}

// GetPort gets the port tagged with the given name. If the value is not set, it returns 0.
func (m *ConfigRequest) GetPort(name string) (uint16, error) {
	switch name {
	case "service":
		v0 := m.V1
		if v0 == nil {
			return 0, nil
		}
		v1 := v0.Sys
		if v1 == nil {
			return 0, nil
		}
		v2 := v1.Service
		if v2 == nil {
			return 0, nil
		}
		v3 := v2.Port
		return uint16(v3.GetValue()), nil
	default:
		return 0, a2conf.ErrPortNotFound
	}
}

// ListSecrets lists all the secrets exposed by the config
func (m *ConfigRequest) ListSecrets() []a2conf.SecretInfo {
	return []a2conf.SecretInfo{a2conf.SecretInfo{
		EnvironmentVariable: "AUTOMATE_SECRET_AWS_OS_PASSWORD",
		Name:                "aws_os_password",
	}}
}

// GetSecret gets a secret by name. Returns nil if it is not set
func (m *ConfigRequest) GetSecret(name string) *wrappers.StringValue {
	if m == nil {
		return nil
	}
	switch name {
	case "aws_os_password":
		v0 := m.V1
		if v0 == nil {
			return nil
		}
		v1 := v0.Sys
		if v1 == nil {
			return nil
		}
		v2 := v1.Backups
		if v2 == nil {
			return nil
		}
		v3 := v2.S3
		if v3 == nil {
			return nil
		}
		v4 := v3.AwsAuth
		if v4 == nil {
			return nil
		}
		v5 := v4.Password
		return v5
	default:
		return nil
	}
}

// SetSecret sets a secret by name. Returns ErrSecretNotFound if the secret does not exist
func (m *ConfigRequest) SetSecret(name string, value *wrappers.StringValue) error {
	switch name {
	case "aws_os_password":
		v0 := &m.V1
		if *v0 == nil {
			*v0 = &ConfigRequest_V1{}
		}
		v1 := &(*v0).Sys
		if *v1 == nil {
			*v1 = &ConfigRequest_V1_System{}
		}
		v2 := &(*v1).Backups
		if *v2 == nil {
			*v2 = &ConfigRequest_V1_System_Backups{}
		}
		v3 := &(*v2).S3
		if *v3 == nil {
			*v3 = &ConfigRequest_V1_System_Backups_S3Settings{}
		}
		v4 := &(*v3).AwsAuth
		if *v4 == nil {
			*v4 = &shared.External_Opensearch_Authentication_AwsOpensearchAuth{}
		}
		v5 := &(*v4).Password
		if *v5 == nil {
			*v5 = &wrapperspb.StringValue{}
		}
		*v5 = value
	default:
		return a2conf.ErrSecretNotFound
	}
	return nil
}
