package catalogpublication

import (
	"context"
	"fmt"

	catalogassignmentidentityv1 "github.com/pingcap-inc/nexuscrm-contract/pkg/catalogassignmentidentityv1"
	"github.com/pingcap-inc/nexuscrm-controlplane/internal/catalogassignmentidentity"
)

// StoreAssignmentIdentityView appends one complete immutable assignment view
// through the Catalog publication owner. It creates no mutable selector and an
// exact retry returns the same content digest.
func (a *Authority) StoreAssignmentIdentityView(
	ctx context.Context,
	view catalogassignmentidentityv1.View,
) (string, error) {
	store, err := catalogassignmentidentity.New(a.db)
	if err != nil {
		return "", err
	}
	digest, err := store.PutExact(ctx, view)
	if err != nil {
		return "", fmt.Errorf("store Catalog assignment identity view: %w", err)
	}
	return digest, nil
}
