package com.openosrs.client.scripting;

import java.util.HashMap;
import java.util.Map;

/**
 * Configuration for script execution.
 */
public class ScriptConfiguration {
    private final int maxConcurrentScripts;
    private final long maxRuntime;
    private final boolean scheduled;
    private final long initialDelay;
    private final long repeatInterval;
    private final Map<String, Object> parameters;
    private final boolean logExecution;
    
    public ScriptConfiguration() {
        this.maxConcurrentScripts = 10;
        this.maxRuntime = 0; // No limit
        this.scheduled = false;
        this.initialDelay = 0;
        this.repeatInterval = 0;
        this.parameters = new HashMap<>();
        this.logExecution = true;
    }
    
    public ScriptConfiguration(int maxConcurrentScripts, long maxRuntime, 
                              boolean scheduled, long initialDelay, long repeatInterval,
                              Map<String, Object> parameters, boolean logExecution) {
        this.maxConcurrentScripts = maxConcurrentScripts;
        this.maxRuntime = maxRuntime;
        this.scheduled = scheduled;
        this.initialDelay = initialDelay;
        this.repeatInterval = repeatInterval;
        this.parameters = new HashMap<>(parameters);
        this.logExecution = logExecution;
    }
    
    public int getMaxConcurrentScripts() { return maxConcurrentScripts; }
    public long getMaxRuntime() { return maxRuntime; }
    public boolean isScheduled() { return scheduled; }
    public long getInitialDelay() { return initialDelay; }
    public long getRepeatInterval() { return repeatInterval; }
    public Map<String, Object> getParameters() { return new HashMap<>(parameters); }
    public boolean isLogExecution() { return logExecution; }
    
    public static class Builder {
        private int maxConcurrentScripts = 10;
        private long maxRuntime = 0;
        private boolean scheduled = false;
        private long initialDelay = 0;
        private long repeatInterval = 0;
        private Map<String, Object> parameters = new HashMap<>();
        private boolean logExecution = true;
        
        public Builder maxConcurrentScripts(int maxConcurrentScripts) {
            this.maxConcurrentScripts = maxConcurrentScripts;
            return this;
        }
        
        public Builder maxRuntime(long maxRuntime) {
            this.maxRuntime = maxRuntime;
            return this;
        }
        
        public Builder scheduled(long initialDelay, long repeatInterval) {
            this.scheduled = true;
            this.initialDelay = initialDelay;
            this.repeatInterval = repeatInterval;
            return this;
        }
        
        public Builder parameter(String key, Object value) {
            this.parameters.put(key, value);
            return this;
        }
        
        public Builder logExecution(boolean logExecution) {
            this.logExecution = logExecution;
            return this;
        }
        
        public ScriptConfiguration build() {
            return new ScriptConfiguration(maxConcurrentScripts, maxRuntime, 
                scheduled, initialDelay, repeatInterval, parameters, logExecution);
        }
    }
}