package bridge

import (
	"os"
	"strconv"
	"strings"
)

type Config struct {
	IntegratorName     string
	CCIPSupportedPairs map[string]bool
}

func DefaultConfig() *Config {
	integrator := os.Getenv("BRIDGE_INTEGRATOR")
	if integrator == "" {
		integrator = "explorer-bridge-aggregator"
	}
	pairsStr := os.Getenv("CCIP_SUPPORTED_PAIRS")
	if pairsStr == "" {
		pairsStr = "138-1,1-138"
	}
	pairs := make(map[string]bool)
	for _, p := range strings.Split(pairsStr, ",") {
		p = strings.TrimSpace(p)
		if p != "" {
			pairs[p] = true
		}
	}
	return &Config{IntegratorName: integrator, CCIPSupportedPairs: pairs}
}

func (c *Config) SupportsCCIPRoute(fromChain, toChain int) bool {
	if c == nil || c.CCIPSupportedPairs == nil {
		return false
	}
	return c.CCIPSupportedPairs[strconv.Itoa(fromChain)+"-"+strconv.Itoa(toChain)]
}
