<?php
class HeadersHelper{
    /**
     * [getHeader description]
     * @param  array[] $headers headers array ex: [column_name => column_alias]
     * @param  string $type    type of the return it can have values sql or array
     * @return strin|array return sql header if type is sql and array of headers if type is array
     */
    public function getHeader($headers = [], $type = 'array'){
        $method = 'generate' . ucfirst($type) . 'Header';
        return $this->{$method}($headers);
    }

    /**
     * generates required header string for an sql (columns to be fetch from DB)
     * @param  array $headers headers array
     * @return string  sql columns string
     */
    private function generateSqlHeader($headers){
        $formattedHeader = '';
        foreach ($headers as $key => $value) {
            $formattedHeader .= $key . ' AS ' . $value . ',';
        }
        return rtrim($formattedHeader, ',');
    }

    /**
     * generates an  integer indexed array for the headers
     * @param  array $headers headers array
     * @return array         array of values for the header
     */
    private function generateArrayHeader($headers){
        $formattedHeader = [];
        foreach ($headers as $value) {
            array_push($formattedHeader, $value);
        }

        return $formattedHeader;
    }

}
