package ctbrec.recorder.download.hls;

import java.time.Duration;
import java.time.ZoneId;
import java.time.ZonedDateTime;

import ctbrec.Settings;
import ctbrec.recorder.download.Download;
import ctbrec.recorder.download.SplittingStrategy;

public class TimeSplittingStrategy implements SplittingStrategy {

    private Settings settings;

    @Override
    public void init(Settings settings) {
        this.settings = settings;
    }

    @Override
    public boolean splitNecessary(Download download) {
        ZonedDateTime startTime = download.getStartTime().atZone(ZoneId.systemDefault());
        Duration recordingDuration = Duration.between(startTime, ZonedDateTime.now());
        long seconds = recordingDuration.getSeconds();
        return seconds >= settings.splitRecordingsAfterSecs;
    }

}
