<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Log extends Api_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function getMainData()
    {
        $type = $this->input->post('type');

        if (!isset($type)) {
            $this->FailedResponse('Invalid Param');
        }

        $val_type = $this->getTypeString($type);

        if(!$val_type) {
            $this->FailedResponse("Invalid Type");
        }

        $data = $this->getLogModel()->get_by(array(
            Type => $val_type
        ), false);
        if ($data) {
            $this->SuccessResponse($data);
        } else {
            $this->FailedResponse("There is no item yet");
        }
    }

    public function getSubData()
    {
        $type = $this->input->post('type');
        $ref = $this->input->post('reference_no');

        if (!isset($type, $ref)) {
            $this->FailedResponse('Invalid Param');
        }

        $val_type = $this->getTypeString($type);

        if(!$val_type) {
            $this->FailedResponse("Invalid Type");
        }

        $data = $this->getLogModel()->get_by(array(
            Type => $val_type,
            Reference_No => $ref
        ), false);
        if ($data) {
            $this->SuccessResponse($data);
        } else {
            $this->FailedResponse("There is no item yet");
        }
    }
}