package policiesdb

import (
	"context"

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

func (db *PoliciesDB) All(ctx context.Context, organizationRef bson.ObjectID) ([]model.PolicyDescription, error) {
	// all documents
	filter := repository.Query().Or(
		repository.Filter(storable.OrganizationRefField, nil),
		repository.OrgFilter(organizationRef),
	)
	return mutil.GetObjects[model.PolicyDescription](ctx, db.Logger, filter, nil, db.Repository)
}
