// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package print

import (
	"code.gitea.io/sdk/gitea"
)

// ReleasesList prints a listing of releases
func ReleasesList(releases []*gitea.Release, output string) error {
	t := tableWithHeader(
		"Tag-Name",
		"Title",
		"Published At",
		"Status",
		"Tar/Zip URL",
	)

	for _, release := range releases {
		status := "released"
		if release.IsDraft {
			status = "draft"
		} else if release.IsPrerelease {
			status = "prerelease"
		}
		t.addRow(
			release.TagName,
			release.Title,
			FormatTime(release.PublishedAt, isMachineReadable(output)),
			status,
			release.TarURL+"\n"+release.ZipURL,
		)
	}

	return t.print(output)
}
