/* © SRSoftware 2025 */
package de.srsoftware.umbrella.message.model;

import static de.srsoftware.umbrella.core.constants.Field.HOURS;
import static java.util.stream.Collectors.joining;

import java.util.Collection;
import java.util.HashSet;
import java.util.Map;

public class Schedule implements Settings{

	private final HashSet<Integer> hours;

	private Schedule(Collection<Integer> hours){
		this.hours = new HashSet<>(hours);
	}

	public static Settings schedule(Collection<Integer> hours){
		return hours == null || hours.isEmpty() ? new Silent() : new Schedule(hours);
	}

	@Override
	public boolean sendAt(Integer scheduledHour) {
		return scheduledHour != null && hours.contains(scheduledHour);
	}

	@Override
	public Map<String, Object> toMap() {
		return Map.of(HOURS,hours);
	}

	@Override
	public String toString() {
		return hours.stream().map(Object::toString).collect(joining(","));
	}
}
