package convert

import (
	repo_model "code.gitea.io/gitea/models/repo"
	"code.gitea.io/gitea/modules/context"
	gitea_api "code.gitea.io/gitea/modules/structs"
	gitea_convert "code.gitea.io/gitea/services/convert"
	api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
)

func ToRelease(ctx *context.APIContext, r *repo_model.Release) *api.Release {
	assets := make([]*gitea_api.Attachment, 0)
	for _, att := range r.Attachments {
		assets = append(assets, gitea_convert.ToAttachment(ctx.Repo.Repository, att))
	}
	return &api.Release{
		ID:           r.ID,
		TagName:      r.TagName,
		Target:       r.Target,
		Title:        r.Title,
		Sha:          r.Sha1,
		Note:         r.Note,
		URL:          r.APIURL(),
		HTMLURL:      r.HTMLURL(),
		TarURL:       r.TarURL(),
		ZipURL:       r.ZipURL(),
		IsDraft:      r.IsDraft,
		IsPrerelease: r.IsPrerelease,
		CreatedAt:    r.CreatedUnix.AsTime(),
		PublishedAt:  r.CreatedUnix.AsTime(),
		Publisher:    gitea_convert.ToUser(ctx, r.Publisher, nil),
		Attachments:  assets,
	}
}
