package api

import (
	"encoding/json"
	"net/http"

	"github.com/tidbcloud/account/internel/svc/migrate"

	"github.com/tidbcloud/account/pkg/version"
)

type versionInfo struct {
	Hash             string `json:"hash"`
	CentralDBVersion int    `json:"central_db_version"`
	TenantDBVersion  int    `json:"tenant_db_version"`
}

// VersionHandler outputs the current central server version information.
func VersionHandler(w http.ResponseWriter, _ *http.Request) {
	data, _ := json.Marshal(versionInfo{
		Hash:             version.GitHash,
		CentralDBVersion: migrate.GetCentralDBVersion(),
	})
	_, _ = w.Write(data)
}
