package repository

import (
	"context"

	"eslogad-be/internal/entities"

	"gorm.io/gorm"
)

type TitleRepository struct {
	db *gorm.DB
}

func NewTitleRepository(db *gorm.DB) *TitleRepository {
	return &TitleRepository{db: db}
}

func (r *TitleRepository) ListAll(ctx context.Context) ([]entities.Title, error) {
	var titles []entities.Title
	if err := r.db.WithContext(ctx).Order("name ASC").Find(&titles).Error; err != nil {
		return nil, err
	}
	return titles, nil
}
