package at.procon.dip.domain.access;

import at.procon.dip.domain.tenant.TenantRef;
import java.util.Objects;

/**
 * Canonical ownership and visibility descriptor for a document.
 * <p>
 * A document may have no owner tenant, for example public TED notices.
 * Visibility is always mandatory and defines who may search/read the document.
 */
public record DocumentAccessContext(
        TenantRef ownerTenant,
        DocumentVisibility visibility
) {

    public DocumentAccessContext {
        Objects.requireNonNull(visibility, "visibility must not be null");
    }

    public static DocumentAccessContext publicDocument() {
        return new DocumentAccessContext(null, DocumentVisibility.PUBLIC);
    }

    public static DocumentAccessContext tenantOwned(TenantRef ownerTenant) {
        return new DocumentAccessContext(
                Objects.requireNonNull(ownerTenant, "ownerTenant must not be null"),
                DocumentVisibility.TENANT
        );
    }
}
