package transform

import (
	"fmt"

	"github.com/pingcap/agent-git-service/internal/db"
)

// Team converts a db.Team to a GitHub REST API team object.
func (t Transformer) Team(team db.Team) map[string]any {
	htmlURL := fmt.Sprintf("%s/orgs/%s/teams/%s", t.htmlBase(), team.Organization.Login, team.Slug)
	return map[string]any{
		"id":               team.ID,
		"node_id":          NodeID("Team", team.ID),
		"url":              fmt.Sprintf("%s/orgs/%s/teams/%s", t.APIBase(), team.Organization.Login, team.Slug),
		"html_url":         htmlURL,
		"name":             team.Name,
		"slug":             team.Slug,
		"description":      team.Description,
		"privacy":          db.TeamPrivacyClosed,
		"permission":       "pull", // default
		"members_count":    team.MembersCount,
		"repos_count":      team.ReposCount,
		"members_url":      fmt.Sprintf("%s/orgs/%s/teams/%s/members{/member}", t.APIBase(), team.Organization.Login, team.Slug),
		"repositories_url": fmt.Sprintf("%s/orgs/%s/teams/%s/repos", t.APIBase(), team.Organization.Login, team.Slug),
	}
}
