package discovery

import (
	"context"

	"github.com/ultisuite/ulti-backend/internal/nextcloud"
)

type ncAdapter struct {
	nc *nextcloud.Client
}

func NewNCAdapter(nc *nextcloud.Client) *ncAdapter {
	return &ncAdapter{nc: nc}
}

func (a *ncAdapter) ListContacts(ctx context.Context, userID, bookPath string) ([]ncContact, error) {
	contacts, err := a.nc.ListContacts(ctx, userID, bookPath)
	if err != nil {
		return nil, err
	}
	out := make([]ncContact, 0, len(contacts))
	for _, c := range contacts {
		out = append(out, ncContact{
			UID:      c.UID,
			FullName: c.FullName,
			Email:    c.Email,
			Phone:    c.Phone,
			Org:      c.Org,
		})
	}
	return out, nil
}
