"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var RedisModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisModule = void 0;
const common_1 = require("@nestjs/common");
const redis_service_1 = require("./redis.service");
const ioredis_1 = __importDefault(require("ioredis"));
let RedisModule = RedisModule_1 = class RedisModule {
    static forRoot(options) {
        return {
            module: RedisModule_1,
            providers: [
                {
                    provide: 'REDIS_OPTIONS',
                    useValue: options,
                },
                {
                    provide: 'REDIS',
                    useFactory: async () => {
                        return new ioredis_1.default({
                            host: options.host,
                            port: options.port,
                            password: options.password,
                            db: options.db || 0,
                        });
                    },
                },
                redis_service_1.RedisService,
            ],
            exports: [redis_service_1.RedisService, 'REDIS'],
        };
    }
    static forRootAsync(options) {
        return {
            module: RedisModule_1,
            imports: options.imports || [],
            providers: [
                {
                    provide: 'REDIS_OPTIONS',
                    useFactory: options.useFactory,
                    inject: options.inject || [],
                },
                {
                    provide: 'REDIS',
                    useFactory: async (opt) => {
                        return new ioredis_1.default(opt);
                    },
                    inject: ['REDIS_OPTIONS'],
                },
                redis_service_1.RedisService,
            ],
            exports: [redis_service_1.RedisService, 'REDIS'],
        };
    }
};
exports.RedisModule = RedisModule;
exports.RedisModule = RedisModule = RedisModule_1 = __decorate([
    (0, common_1.Global)(),
    (0, common_1.Module)({})
], RedisModule);
//# sourceMappingURL=redis.module.js.map