package kv

import (
	"context"

	"github.com/tech/sendico/pkg/mlogger"
)

// Config describes Vault KV v2 connection settings.
type Config struct {
	Address      string `mapstructure:"address" yaml:"address"`
	TokenEnv     string `mapstructure:"token_env" yaml:"token_env"`
	TokenFileEnv string `mapstructure:"token_file_env" yaml:"token_file_env"`
	TokenFile    string `mapstructure:"token_file" yaml:"token_file"`
	Namespace    string `mapstructure:"namespace" yaml:"namespace"`
	MountPath    string `mapstructure:"mount_path" yaml:"mount_path"`
}

// Client defines KV operations used by services.
type Client interface {
	Put(ctx context.Context, secretPath string, payload map[string]interface{}) error
	Get(ctx context.Context, secretPath string) (map[string]interface{}, error)
	GetString(ctx context.Context, secretPath, field string) (string, error)
}

// Options configure KV client creation.
type Options struct {
	Logger    mlogger.Logger
	Config    Config
	Component string
}

// New creates a Vault KV v2 client.
func New(opts Options) (Client, error) {
	return newService(opts)
}
