package pipeline

import (
	"fmt"
	"strings"
)

type ChunkCacheMode string

const (
	ChunkCacheAuto    ChunkCacheMode = "auto"
	ChunkCacheBypass  ChunkCacheMode = "bypass"
	ChunkCacheRefresh ChunkCacheMode = "refresh"
)

func ParseChunkCacheMode(raw string) (ChunkCacheMode, error) {
	mode := ChunkCacheMode(strings.TrimSpace(raw))
	switch mode {
	case ChunkCacheAuto, ChunkCacheBypass, ChunkCacheRefresh:
		return mode, nil
	default:
		return "", fmt.Errorf("chunk cache mode %q is not supported", strings.TrimSpace(raw))
	}
}

func (m ChunkCacheMode) Validate() error {
	_, err := ParseChunkCacheMode(string(m))
	return err
}
