/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.gravitino.maintenance.optimizer.api.recommender;

import java.util.Optional;

/**
 * Encapsulates the scored result and job execution context for a single strategy evaluation. The
 * recommender ranks evaluations by {@link #score()} before asking the {@link
 * org.apache.gravitino.maintenance.optimizer.api.recommender.JobSubmitter JobSubmitter} to launch
 * work.
 */
public interface StrategyEvaluation {

  /**
   * Evaluation placeholder indicating that no execution should happen. It uses score {@code -1} and
   * an empty job execution context.
   */
  StrategyEvaluation NO_EXECUTION =
      new StrategyEvaluation() {
        @Override
        public long score() {
          return -1L;
        }

        @Override
        public Optional<JobExecutionContext> jobExecutionContext() {
          return Optional.empty();
        }
      };

  /**
   * Score used to rank multiple recommendations of the same strategy. Higher wins; equal scores
   * preserve the evaluation order returned by the {@code StrategyHandler}.
   */
  long score();

  /**
   * Job execution context for this evaluation. Implementations return {@link Optional#empty()} when
   * {@link #NO_EXECUTION} is used to signal that no job should be submitted.
   */
  Optional<JobExecutionContext> jobExecutionContext();
}
