package repository

import (
	"context"

	entity "gitlab.com/mbugroup/lti-api.git/internal/entities"

	"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
	"gorm.io/gorm"
)

type AreaRepository interface {
	repository.BaseRepository[entity.Area]
	NameExists(ctx context.Context, name string, excludeID *uint) (bool, error)
}

type AreaRepositoryImpl struct {
	*repository.BaseRepositoryImpl[entity.Area]
	db *gorm.DB
}

func NewAreaRepository(db *gorm.DB) AreaRepository {
	return &AreaRepositoryImpl{
		BaseRepositoryImpl: repository.NewBaseRepository[entity.Area](db),
		db:                 db,
	}
}

func (r *AreaRepositoryImpl) NameExists(ctx context.Context, name string, excludeID *uint) (bool, error) {
	return repository.ExistsByName[entity.Area](ctx, r.db, name, excludeID)
}
