"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 __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var SmsService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SmsService = void 0;
const common_1 = require("@nestjs/common");
const smsglobal = require("smsglobal");
let SmsService = SmsService_1 = class SmsService {
    constructor() {
        this.logger = new common_1.Logger(SmsService_1.name);
        const apiKey = "e2f3cd1dcb66b0fbd4d06d6f9e3b2706";
        const apiSecret = "3b5e9be418e895060ab9ae14f43b5a2e";
        if (!apiKey || !apiSecret) {
            this.logger.error('SMSGlobal API credentials are missing!');
            throw new Error('SMSGlobal API credentials are required in .env');
        }
        this.logger.log(`SMSGLOBAL_API_KEY: ${apiKey}`);
        this.logger.log(`SMSGLOBAL_API_SECRET: ${apiSecret}`);
        this.smsClient = smsglobal(apiKey, apiSecret);
    }
    async sendOtp(phoneNumber, otp, hash) {
        const payload = {
            origin: 'RKNAlwejdan',
            destination: phoneNumber,
            message: `Your OTP for verifying your account is <#> Cars24x7: ${otp} \n${hash}. It will expire in 10 minutes. Don’t share this code with anyone.`,
        };
        return new Promise((resolve, reject) => {
            this.smsClient.sms.send(payload, (error, response) => {
                if (error) {
                    this.logger.error(`Failed to send OTP: ${JSON.stringify(error)}`);
                    return reject(error);
                }
                this.logger.log(`OTP sent to ${phoneNumber}: ${JSON.stringify(response)}`);
                resolve(response);
            });
        });
    }
};
exports.SmsService = SmsService;
exports.SmsService = SmsService = SmsService_1 = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [])
], SmsService);
//# sourceMappingURL=sms.service.js.map