package accountdb

import (
	"context"

	"github.com/tech/sendico/pkg/db/repository"
	"github.com/tech/sendico/pkg/db/repository/builder"
	"github.com/tech/sendico/pkg/model"
	mutil "github.com/tech/sendico/pkg/mutil/db"
	"go.mongodb.org/mongo-driver/v2/bson"
)

func (db *AccountDB) GetAccountsByRefs(ctx context.Context, orgRef bson.ObjectID, refs []bson.ObjectID) ([]model.Account, error) {
	filter := repository.Query().Comparison(repository.IDField(), builder.In, refs)
	return mutil.GetObjects[model.Account](ctx, db.Logger, filter, nil, db.Repository)
}

func (db *AccountDB) GetByEmail(ctx context.Context, email string) (*model.Account, error) {
	var account model.Account
	return &account, db.FindOne(ctx, repository.Filter("login", email), &account)
}
