/*
 * Copyright 2021-2022 the original author or authors.
 *
 * Licensed 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
 *
 *      https://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.opentest4j.reporting.events.root;

import org.opentest4j.reporting.events.api.Factory;
import org.opentest4j.reporting.events.java.HeapSize;

import java.time.Instant;

/**
 * Factory for elements of the events namespace.
 */
public class RootFactory {

	private RootFactory() {
	}

	/**
	 * Create a factory for {@link Started} elements.
	 *
	 * @param id   test id (unique within the test run)
	 * @param time time of the event
	 * @param name test name
	 * @return Started factory
	 */
	public static Factory<Started> started(String id, Instant time, String name) {
		return context -> new Started(context).withId(id).withTime(time).withName(name);
	}

	/**
	 * Create a factory for {@link Reported} elements.
	 *
	 * @param id   test id (must match id of previous {@link Started} element)
	 * @param time time of the event
	 * @return Reported factory
	 */
	public static Factory<Reported> reported(String id, Instant time) {
		return context -> new Reported(context).withId(id).withTime(time);
	}

	/**
	 * Create a factory for {@link Finished} elements.
	 *
	 * @param id   test id (must match id of previous {@link Started} element)
	 * @param time time of the event
	 * @return Finished factory
	 */
	public static Factory<Finished> finished(String id, Instant time) {
		return context -> new Finished(context).withId(id).withTime(time);
	}
}
