package config

import (
	
	
)

// DefaultFileName is the configuration file loaded from the repository root.
const DefaultFileName = "goship.json"

// DefaultCommitTemplate is the default Go text/template used for dependency
// update commit messages.
const DefaultCommitTemplate = `{{- if eq (len .Deps) 1 -}}
{{- with index .Deps 0 -}}chore: bump {{.Module}} to {{.Version}}{{- end -}}
{{- else -}}
chore: bump workspace dependencies
{{range .Deps}}
- {{.Module}}@{{.Version}}{{end}}
{{- end -}}`

// DefaultTagTemplate is the default Go text/template used for tag messages.
const DefaultTagTemplate = "Release {{.Module}} {{.Version}}"

// CheckMode controls API compatibility verification during plan and run.
type CheckMode string

const (
	// CheckOff disables apidiff compatibility checking (default).
	CheckOff CheckMode = "off"
	// CheckWarn reports semver compatibility violations as warnings.
	CheckWarn CheckMode = "warn"
	// CheckError fails planning when semver compatibility is violated.
	CheckError CheckMode = "error"
)

// ParseCheckMode validates a check mode string.
func ( string) (CheckMode, error) {
	switch  := CheckMode();  {
	case "", CheckOff:
		return CheckOff, nil
	case CheckWarn, CheckError:
		return , nil
	default:
		return "", fmt.Errorf("invalid check mode %q (expected off, warn, or error)", )
	}
}

// Config holds repository-level configuration for goship. The zero value uses
// defaults for all fields.
type Config struct {
	// VCS selects and configures the version control backend.
	VCS VCSConfig `json:"vcs,omitzero"`

	// Workspace selects and configures how Go modules are loaded.
	Workspace WorkspaceConfig `json:"workspace,omitzero"`

	// Check controls apidiff semver compatibility checks ("off", "warn", "error").
	Check CheckMode `json:"check,omitzero"`

	// Include restricts selection to modules matching at least one glob pattern
	// (matched against both module path and repo-relative directory).
	Include []string `json:"include,omitzero"`

	// Exclude skips modules matching any glob pattern (matched against both
	// module path and repo-relative directory).
	Exclude []string `json:"exclude,omitzero"`

	// ExcludeVersions skips any module that requires a dependency at one of
	// these exact versions (for example, fake integration-test versions).
	ExcludeVersions []string `json:"excludeVersions,omitzero"`

	// CommitTemplate is a Go text/template for dependency-bump commit messages.
	CommitTemplate string `json:"commitTemplate,omitzero"`

	// TagTemplate is a Go text/template for tag messages.
	TagTemplate string `json:"tagTemplate,omitzero"`

	// Remote optionally overrides the VCS’s default remote used by -push.
	// An empty value delegates to each VCS backend’s own default remote.
	Remote string `json:"remote,omitzero"`
}

// Parse strictly parses JSON configuration bytes using encoding/json/v2.
func ( []byte) (Config, error) {
	var  Config
	if  := json.Unmarshal(, &, json.RejectUnknownMembers(true));  != nil {
		return Config{}, fmt.Errorf("parse config: %w", )
	}
	if ,  := ParseCheckMode(string(.Check));  != nil {
		return Config{}, fmt.Errorf("parse config: %w", )
	}
	return , nil
}