<?php

class PaginatedResponse extends BaseResponse
{
    protected $result;
    protected $totalRecord;
    protected $limit;
    protected $offset;
    protected $additional_params;

    public function __construct($result, $totalRecord, $limit, $offset, $additional_params = null)
    {
        $this->result = $result;
        $this->totalRecord = $totalRecord;
        $this->limit = $limit;
        $this->offset = $offset;
        $this->additional_params = $additional_params;
    }

    public function buildBody() {
        $response = [
            'success' => true,
            'data' =>[
                'total_record' => $this->totalRecord,
			    'per_page' => (int) $this->limit,
			    'total_page'	=> $this->limit == 0 ? 0 : ceil($this->totalRecord/$this->limit),
			    'current_page'	=> $this->limit == 0 ? 0 : floor($this->offset / $this->limit) + 1,
                'result'		=> $this->result
            ]			
        ];

        if(!empty($this->additional_params) && is_array($this->additional_params)) {
            $response = array_merge($response, $this->additional_params);
        }

        return $response;
    }

    public function getStatusCode() {
        return 200;
    }
}