import getAppDataPath from 'appdata-path';


class Config {
    public readonly localConfig: {
        folder: string; sessionFile: string; stateFile: string;
    };

    public readonly versionUpdateInformationPeriodHours: number;

    public readonly gitlab: {
        cliReleasePage: string
        cliPreAlphaReleasePage: string
    };

    public readonly login: {
        server: {
            port: number, route: string
        }, gitlab: {
            url: {
                code: string
            }
        }
    };

    public readonly folders: {
        defaultLocalExercise: string
    };

    public readonly exercise: {
        neededFiles: Array<string>
    };

    public interactiveMode: boolean;

    constructor() {
        this.localConfig = {
            folder     : getAppDataPath('DojoCLI'),
            sessionFile: process.env.LOCAL_CONFIG_FILE_SESSION || '',
            stateFile  : process.env.LOCAL_CONFIG_STATE || ''
        };

        this.versionUpdateInformationPeriodHours = Number(process.env.VERSION_UPDATE_INFORMATION_PERIOD_HOURS || 24);

        this.gitlab = {
            cliReleasePage        : process.env.GITLAB_CLI_RELEASE_PAGE || '',
            cliPreAlphaReleasePage: process.env.GITLAB_CLI_PREALPHA_RELEASE_PAGE || ''
        };

        this.login = {
            server: {
                port : Number(process.env.LOGIN_SERVER_PORT || 30992),
                route: process.env.LOGIN_SERVER_ROUTE || ''
            },
            gitlab: {
                url: {
                    code: process.env.LOGIN_GITLAB_URL_CODE || ''
                }
            }
        };

        this.folders = {
            defaultLocalExercise: process.env.LOCAL_EXERCISE_DEFAULT_FOLDER || './'
        };

        this.exercise = {
            neededFiles: JSON.parse(process.env.EXERCISE_NEEDED_FILES || '[]')
        };

        this.interactiveMode = process.env.INTERACTIVE_MODE === 'true';
    }
}


export default new Config();