package convert

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

func ToRelease(r *repo_model.Release) *api.Release {
	assets := make([]*gitea_api.Attachment, 0)
	for _, att := range r.Attachments {
		assets = append(assets, gitea_convert.ToReleaseAttachment(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(r.Publisher, nil),
		Attachments:  assets,
	}
}
