package com.r35157.nenjim.service.journal.model;

import com.r35157.nenjim.service.journal.valuetypes.VersionExpressionSet;

import java.util.Objects;
import java.util.Optional;

/** One inspectable policy, exclusion, or preference line and its description. */
public record PolicyRule(VersionExpressionSet versions, Optional<String> description) {
    public PolicyRule {
        Objects.requireNonNull(versions, "versions");
        if (versions.isEmpty()) {
            throw new IllegalArgumentException("A policy rule must identify at least one version");
        }
        description = Objects.requireNonNull(description, "description");
        description.ifPresent(value -> {
            if (value.isBlank()) {
                throw new IllegalArgumentException("An explicitly supplied rule description cannot be blank");
            }
        });
    }

    public PolicyRule(VersionExpressionSet versions) {
        this(versions, Optional.empty());
    }
}
