package repository

import (
	"context"
	"go-server/internal/models"

	"gorm.io/gorm"
)

type NutrientRepository struct {
	db *gorm.DB
}

func NewNutrientRepository(db *gorm.DB) *NutrientRepository {
	return &NutrientRepository{db: db}
}

func (r *NutrientRepository) GetAll(ctx context.Context) ([]*models.Nutrient, error) {
	var nutrients []*models.Nutrient
	err := r.db.WithContext(ctx).
		Preload("Categories").
		Find(&nutrients).
		Error
	if err != nil {
		return nil, err
	}
	return nutrients, nil
}
