package bunmodel

import (
	"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
	"github.com/uptrace/bun"
)

type Version struct {
	bun.BaseModel `bun:"table:versions,alias:version"`

	Code     string `bun:"code,pk"`
	Name     string `bun:"name"`
	Host     string `bun:"host"`
	Timezone string `bun:"timezone"`
}

func (v Version) ToDomain() (domain.Version, error) {
	return domain.UnmarshalVersionFromDatabase(
		v.Code,
		v.Name,
		v.Host,
		v.Timezone,
	)
}

type Versions []Version

func (vs Versions) ToDomain() (domain.Versions, error) {
	return sliceToDomain(vs)
}
