package com.storycove.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "storycove.solr")
public class SolrProperties {

    private String url = "http://localhost:8983/solr";
    private String username;
    private String password;

    private Cores cores = new Cores();
    private Connection connection = new Connection();
    private Query query = new Query();
    private Commit commit = new Commit();
    private Health health = new Health();

    // Getters and setters
    public String getUrl() { return url; }
    public void setUrl(String url) { this.url = url; }

    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }

    public String getPassword() { return password; }
    public void setPassword(String password) { this.password = password; }

    public Cores getCores() { return cores; }
    public void setCores(Cores cores) { this.cores = cores; }

    public Connection getConnection() { return connection; }
    public void setConnection(Connection connection) { this.connection = connection; }

    public Query getQuery() { return query; }
    public void setQuery(Query query) { this.query = query; }

    public Commit getCommit() { return commit; }
    public void setCommit(Commit commit) { this.commit = commit; }

    public Health getHealth() { return health; }
    public void setHealth(Health health) { this.health = health; }

    public static class Cores {
        private String stories = "storycove_stories";
        private String authors = "storycove_authors";
        private String collections = "storycove_collections";

        // Getters and setters
        public String getStories() { return stories; }
        public void setStories(String stories) { this.stories = stories; }

        public String getAuthors() { return authors; }
        public void setAuthors(String authors) { this.authors = authors; }

        public String getCollections() { return collections; }
        public void setCollections(String collections) { this.collections = collections; }
    }

    public static class Connection {
        private int timeout = 30000;
        private int socketTimeout = 60000;
        private int maxConnectionsPerRoute = 10;
        private int maxConnectionsTotal = 30;
        private boolean retryOnFailure = true;
        private int maxRetries = 3;

        // Getters and setters
        public int getTimeout() { return timeout; }
        public void setTimeout(int timeout) { this.timeout = timeout; }

        public int getSocketTimeout() { return socketTimeout; }
        public void setSocketTimeout(int socketTimeout) { this.socketTimeout = socketTimeout; }

        public int getMaxConnectionsPerRoute() { return maxConnectionsPerRoute; }
        public void setMaxConnectionsPerRoute(int maxConnectionsPerRoute) { this.maxConnectionsPerRoute = maxConnectionsPerRoute; }

        public int getMaxConnectionsTotal() { return maxConnectionsTotal; }
        public void setMaxConnectionsTotal(int maxConnectionsTotal) { this.maxConnectionsTotal = maxConnectionsTotal; }

        public boolean isRetryOnFailure() { return retryOnFailure; }
        public void setRetryOnFailure(boolean retryOnFailure) { this.retryOnFailure = retryOnFailure; }

        public int getMaxRetries() { return maxRetries; }
        public void setMaxRetries(int maxRetries) { this.maxRetries = maxRetries; }
    }

    public static class Query {
        private int defaultRows = 10;
        private int maxRows = 1000;
        private String defaultOperator = "AND";
        private boolean highlight = true;
        private boolean facets = true;

        // Getters and setters
        public int getDefaultRows() { return defaultRows; }
        public void setDefaultRows(int defaultRows) { this.defaultRows = defaultRows; }

        public int getMaxRows() { return maxRows; }
        public void setMaxRows(int maxRows) { this.maxRows = maxRows; }

        public String getDefaultOperator() { return defaultOperator; }
        public void setDefaultOperator(String defaultOperator) { this.defaultOperator = defaultOperator; }

        public boolean isHighlight() { return highlight; }
        public void setHighlight(boolean highlight) { this.highlight = highlight; }

        public boolean isFacets() { return facets; }
        public void setFacets(boolean facets) { this.facets = facets; }
    }

    public static class Commit {
        private boolean softCommit = true;
        private int commitWithin = 1000;
        private boolean waitSearcher = false;

        // Getters and setters
        public boolean isSoftCommit() { return softCommit; }
        public void setSoftCommit(boolean softCommit) { this.softCommit = softCommit; }

        public int getCommitWithin() { return commitWithin; }
        public void setCommitWithin(int commitWithin) { this.commitWithin = commitWithin; }

        public boolean isWaitSearcher() { return waitSearcher; }
        public void setWaitSearcher(boolean waitSearcher) { this.waitSearcher = waitSearcher; }
    }

    public static class Health {
        private int checkInterval = 30000;
        private int slowQueryThreshold = 5000;
        private boolean enableMetrics = true;

        // Getters and setters
        public int getCheckInterval() { return checkInterval; }
        public void setCheckInterval(int checkInterval) { this.checkInterval = checkInterval; }

        public int getSlowQueryThreshold() { return slowQueryThreshold; }
        public void setSlowQueryThreshold(int slowQueryThreshold) { this.slowQueryThreshold = slowQueryThreshold; }

        public boolean isEnableMetrics() { return enableMetrics; }
        public void setEnableMetrics(boolean enableMetrics) { this.enableMetrics = enableMetrics; }
    }
}