package protocol

import (
	"encoding/json"
	"xboard-go/internal/model"
)

type SingBoxConfig struct {
	Outbounds []map[string]interface{} `json:"outbounds"`
}

func GenerateSingBox(servers []model.Server, user model.User) (string, error) {
	config := SingBoxConfig{
		Outbounds: []map[string]interface{}{},
	}

	// Add selector outbound
	selector := map[string]interface{}{
		"type": "selector",
		"tag":  "Proxy",
		"outbounds": []string{},
	}

	for _, s := range servers {
		outbound := map[string]interface{}{
			"type": s.Type,
			"tag":  s.Name,
			"server": s.Host,
			"server_port": s.Port,
		}
		// Add protocol-specific settings
		// ... logic to handle VMess, Shadowsocks, etc.
		
		config.Outbounds = append(config.Outbounds, outbound)
		selector["outbounds"] = append(selector["outbounds"].([]string), s.Name)
	}

	config.Outbounds = append(config.Outbounds, selector)

	data, err := json.MarshalIndent(config, "", "  ")
	return string(data), err
}
