package p.studio.shipper;

import java.time.Instant;
import java.util.Objects;

public record StudioShipperLogEntry(
        StudioShipperLogSource source,
        StudioShipperLogLevel level,
        String message,
        Instant timestamp) {

    public StudioShipperLogEntry {
        Objects.requireNonNull(source, "source");
        Objects.requireNonNull(level, "level");
        message = Objects.requireNonNull(message, "message").trim();
        timestamp = timestamp == null ? Instant.now() : timestamp;
        if (message.isBlank()) {
            throw new IllegalArgumentException("message must not be blank");
        }
    }

    public static StudioShipperLogEntry info(
            final StudioShipperLogSource source,
            final String message) {
        return new StudioShipperLogEntry(source, StudioShipperLogLevel.INFO, message, Instant.now());
    }

    public static StudioShipperLogEntry error(
            final StudioShipperLogSource source,
            final String message) {
        return new StudioShipperLogEntry(source, StudioShipperLogLevel.ERROR, message, Instant.now());
    }
}
