package apimodel

import "gitea.dwysokinski.me/twhelp/corev3/internal/domain"

func NewVersion(v domain.Version) Version {
	return Version{
		Code:     v.Code(),
		Host:     v.Host(),
		Name:     v.Name(),
		Timezone: v.Timezone(),
	}
}

func NewListVersionsResponse(res domain.ListVersionsResult) ListVersionsResponse {
	versions := res.Versions()

	resp := ListVersionsResponse{
		Data: make([]Version, 0, len(versions)),
		Cursor: Cursor{
			Next: res.Next().Encode(),
			Self: res.Self().Encode(),
		},
	}

	for _, v := range versions {
		resp.Data = append(resp.Data, NewVersion(v))
	}

	return resp
}

func NewGetVersionResponse(v domain.Version) GetVersionResponse {
	return GetVersionResponse{
		Data: NewVersion(v),
	}
}
