package com.atlassian.stash.internal.scheduling;

import com.atlassian.bitbucket.timezone.TimeZoneService;
import com.atlassian.scheduler.caesium.spi.CaesiumSchedulerConfiguration;

import javax.annotation.Nullable;
import java.util.TimeZone;

public class ApplicationCaesiumSchedulerConfiguration implements CaesiumSchedulerConfiguration {

    private final TimeZoneService timeZoneService;
    private final int refreshIntervalInMinutes;
    private final int workerThreadCount;

    public ApplicationCaesiumSchedulerConfiguration(TimeZoneService timeZoneService,
                                                    int refreshIntervalInMinutes,
                                                    int workerThreadCount) {
        this.timeZoneService = timeZoneService;
        this.refreshIntervalInMinutes = refreshIntervalInMinutes;
        this.workerThreadCount = workerThreadCount;
    }

    @Nullable
    @Override
    public TimeZone getDefaultTimeZone() {
        return TimeZone.getTimeZone(timeZoneService.getDefaultTimeZone());
    }

    @Override
    public int refreshClusteredJobsIntervalInMinutes() {
        return refreshIntervalInMinutes;
    }

    @Override
    public int workerThreadCount() {
        return workerThreadCount;
    }

    @Override
    public boolean useFineGrainedSchedules() {
        return true;
    }

    @Override
    public boolean useQuartzJobDataMapMigration() {
        return false;
    }

}
