package vs;

import io.quarkus.grpc.GrpcService;
import io.smallrye.mutiny.Uni;

import vs.Syslog;
import vs.SyslogOuterClass.Message;
import vs.SyslogOuterClass.Result;
import vs.SyslogOuterClass.Severity;

@GrpcService
public class SyslogService implements Syslog {

    @Override
    public Uni<Result> checkUrgency(Message message) {
        boolean urgency = false;
        if (message.getPriority() == Severity.Alert
                || message.getPriority() == Severity.Critical) {
            urgency = true;
        }

        Result result = Result //
                .newBuilder() //
                .setVal(urgency) //
                .build();
        return Uni.createFrom().item(result);
    }

    @Override
    public Uni<Result> log(Message message) {
        System.out.println(message);
        return Uni.createFrom().item(Result//
                .newBuilder() //
                .setVal(true) //
                .build());
    }

}
