package repository

import (
	"context"

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

type CustomerRepository interface {
	repository.BaseRepository[entity.Customer]
	PicExists(ctx context.Context, areaId uint) (bool, error)
	NameExists(ctx context.Context, name string, excludeID *uint) (bool, error)
	IdExists(ctx context.Context, id uint) (bool, error)
}

type CustomerRepositoryImpl struct {
	*repository.BaseRepositoryImpl[entity.Customer]
	db *gorm.DB
}

func NewCustomerRepository(db *gorm.DB) CustomerRepository {
	return &CustomerRepositoryImpl{
		BaseRepositoryImpl: repository.NewBaseRepository[entity.Customer](db),
		db:                 db,
	}
}

func (r *CustomerRepositoryImpl) PicExists(ctx context.Context, picId uint) (bool, error) {
	return repository.Exists[entity.User](ctx, r.db, picId)
}

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

func (r *CustomerRepositoryImpl) IdExists(ctx context.Context, id uint) (bool, error) {
	return repository.Exists[entity.Customer](ctx, r.db, id)
}
