package com.cameleer.server.core.license;

import java.time.Instant;
import java.util.Map;
import java.util.Set;

public record LicenseInfo(
        String tier,
        Set<Feature> features,
        Map<String, Integer> limits,
        Instant issuedAt,
        Instant expiresAt
) {
    public boolean isExpired() {
        return expiresAt != null && Instant.now().isAfter(expiresAt);
    }

    public boolean hasFeature(Feature feature) {
        return features.contains(feature);
    }

    public int getLimit(String key, int defaultValue) {
        return limits.getOrDefault(key, defaultValue);
    }

    /** Open license — all features enabled, no limits. Used when no license is configured. */
    public static LicenseInfo open() {
        return new LicenseInfo("open", Set.of(Feature.values()), Map.of(), Instant.now(), null);
    }
}
