/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

import {Environment} from "./env";
import createRedisClient from "./modules/redis";
import {Redis} from "ioredis";
import {buildImageAggregator} from "./aggregators/image";
import {buildImageComponent} from "./components/image";
import {buildContactAggregator} from "./aggregators/contact";

interface ConfigContext {
    env: Environment
}

export type Config = {
    redisDatabase: Redis,
    redisPub: Redis,
    redisSub: Redis,

    aggregators: {start: () => void}[]
    components: {start: () => void}[]
}

function createConfig({env} : ConfigContext) : Config {
    const redisDatabase = createRedisClient({connectionString: env.redisConnectionString});
    const redisPub = createRedisClient({connectionString: env.redisConnectionString});
    const redisSub = createRedisClient({connectionString: env.redisConnectionString});

    const aggregators : {start: () => void}[] = [
      buildImageAggregator()
    ];

    const components : {start: () => void}[] = [
        buildContactAggregator(),
        buildImageComponent()
    ];

    return {
        redisDatabase,
        redisPub,
        redisSub,

        aggregators,
        components
    }
}

export default createConfig;
