'use strict';

const statusCodes = require('./statusCodes');
const reasonPhrases = require('./reasonPhrases');
const { encryptData } = require('../utils/encryption.util');

class SuccessResponse {
    constructor({
        message,
        statusCode = statusCodes.OK,
        reasonPhrasesCode = reasonPhrases.OK,
        metadata = {},
        pagination,
    }) {
        this.message = !message ? reasonPhrasesCode : message;
        this.statusCode = statusCode;
        this.metadata = metadata;
        if (pagination) {
            this.pagination = pagination;
        }
    }

    send(res, header = {}) {
        return res.status(this.statusCode).json({
            ...this,
            metadata: encryptData(this.metadata),
        });
    }
}

class OK extends SuccessResponse {
    constructor({ message, statusCode = statusCodes.OK, reasonPhrasesCode = reasonPhrases.OK, metadata, pagination }) {
        super({ message, statusCode, reasonPhrasesCode, metadata, pagination });
    }
}

class Created extends SuccessResponse {
    constructor({ message, statusCode = statusCodes.CREATED, reasonPhrasesCode = reasonPhrases.CREATED, metadata }) {
        super({ message, statusCode, reasonPhrasesCode, metadata });
    }
}

module.exports = {
    OK,
    Created,
};
