"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SocialNetworkSmssController = void 0;
const abstract_controller_1 = require("../abstract.controller");
const social_network_sms_model_1 = require("../../models/social-network/social-network-sms.model");
const social_network_sms_method_1 = require("../../methods/social-network/social-network-sms.method");
class SocialNetworkSmssController extends abstract_controller_1.AbstractController {
    constructor() {
        super(social_network_sms_model_1.SocialNetworkSmssModel);
        this.methods = new social_network_sms_method_1.SocialNetworkSmssMethods(social_network_sms_model_1.SocialNetworkSmssModel);
    }
    async sendMessage(req, res) {
        try {
            const matchedData = this.params.matchedData(req);
            this.methods
                .sendMessages(matchedData.list)
                .then((response) => {
                this.model.create();
                this.methods
                    .saveDocument({ ...matchedData, response }, req)
                    .then((r) => {
                    res.send(r);
                })
                    .catch((error) => {
                    this.params.handleHttpError(res, error);
                });
            })
                .catch((error) => {
                this.params.handleHttpError(res, error);
            });
        }
        catch (e) {
            console.log(e);
            this.params.handleHttpError(res, e);
        }
    }
    async sendVerification(req, res) {
        try {
            const matchedData = this.params.matchedData(req);
            this.methods
                .sendVerification(matchedData)
                .then((response) => {
                res.send(response);
            })
                .catch((error) => {
                this.params.handleHttpError(res, error);
            });
        }
        catch (e) {
            console.log(e);
            this.params.handleHttpError(res, e);
        }
    }
    async verify(req, res) {
        try {
            const matchedData = this.params.matchedData(req);
            res.send({
                verify: this.methods.verify(matchedData.number, matchedData.code),
            });
        }
        catch (e) {
            console.log(e);
            this.params.handleHttpError(res, e);
        }
    }
}
exports.SocialNetworkSmssController = SocialNetworkSmssController;
