'use strict';

const _ = require('lodash');

class ControllerResponse {

    constructor(body, code, headers) {
        this.body = body;
        this.headers = headers || [];
        this.code = code;
    }

    header(name) {
        for(let key in this.headers) {

            if(key.toLowerCase() == name.toLowerCase()) {
                return this.headers[key];
            }
        }

        return undefined;
    }

    /* -------------------------------------------------------------------------
     * Utils
     * ---------------------------------------------------------------------- */

    /**
     * @param obj
     * @returns {ControllerResponse}
     */
    static factoryObject(obj) {
        if(obj instanceof ControllerResponse) {
            return obj;
        }

        let req = new ControllerResponse(obj.body, obj.code, obj.headers);

        for(let key in obj) {
            req[key] = obj[key];
        }

        return req;
    }
}

module.exports = ControllerResponse;