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 BankRepository interface {
	repository.BaseRepository[entity.Bank]
	NameExists(ctx context.Context, name string, excludeID *uint) (bool, error)
	AccountNumberExists(ctx context.Context, accountNumber string, excludeID *uint) (bool, error)
}

type BankRepositoryImpl struct {
	*repository.BaseRepositoryImpl[entity.Bank]
	db *gorm.DB
}

func NewBankRepository(db *gorm.DB) BankRepository {
	return &BankRepositoryImpl{
		BaseRepositoryImpl: repository.NewBaseRepository[entity.Bank](db),
		db:                 db,
	}
}

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

func (r *BankRepositoryImpl) AccountNumberExists(ctx context.Context, accountNumber string, excludeID *uint) (bool, error) {
	return repository.ExistsByField[entity.Bank](ctx, r.db, "account_number", accountNumber, excludeID)
}
