package localeSelectorRepo

import (
	"git.ma-al.com/goc_daniel/b2b/app/db"
	"git.ma-al.com/goc_daniel/b2b/app/model"
)

type UILocaleSelectorRepo interface {
	GetLanguages() ([]model.Language, error)
	GetCountriesAndCurrencies() ([]model.Country, error)
}

type LocaleSelectorRepo struct{}

func New() UILocaleSelectorRepo {
	return &LocaleSelectorRepo{}
}

func (r *LocaleSelectorRepo) GetLanguages() ([]model.Language, error) {
	var languages []model.Language
	err := db.Get().Find(&languages).Error
	return languages, err
}

func (r *LocaleSelectorRepo) GetCountriesAndCurrencies() ([]model.Country, error) {
	var countries []model.Country
	err := db.Get().
		Preload("PSCurrency").
		Find(&countries).Error
	return countries, err
}
