package utils

import (
	"strings"

	"github.com/fiskerinc/cloud-services/pkg/utils/envtool"

	az "github.com/Azure/azure-storage-blob-go/azblob"
	"github.com/pkg/errors"
)

type Direction int

const (
	Up Direction = iota
	Down
)

var (
	cursorDirection = map[string]Direction{
		"up":   Up,
		"down": Down,
	}
)

func ParseCursorDirection(str string) (Direction, bool) {
	c, ok := cursorDirection[strings.ToLower(str)]
	return c, ok
}

var (
	AzureAccount               = envtool.GetEnv("AZURE_STORAGE_ACCOUNT", "REPLACE_ME")
	AzureAccountKey            = envtool.GetEnv("AZURE_STORAGE_ACCESS_KEY", "REPLACE_ME")
	AzureTRexLogsContainerName = envtool.GetEnv("AZURE_TREX_LOGS_STORAGE_CONTAINER_NAME", "trex-logs")
	ReadFileName               = "raw.log"

	AzureLogsBlobPath = "https://%s.blob.core.windows.net/%s"
)

func AzureStorageCredential() (*az.SharedKeyCredential, error) {
	cred, err := az.NewSharedKeyCredential(AzureAccount, AzureAccountKey)
	if err != nil {
		return nil, errors.WithStack(err)
	}
	return cred, nil
}
