<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Api\BaseController;

use App\Model\Coverage;

class Controller extends BaseController
{
    public function getCoverageDetail($building_name,$street)
	{
		$data = array();
        $coverage = Coverage::where('building_name',$building_name)->where('street',$street)->get();
		if(!empty($coverage)){
			foreach ($coverage as $key => $c) {
				array_push($data, array(
					'city' => $c->city,
                    'state' => $c->state,
                    'postcode' => $c->postcode,
				));
			}
			return $this->sendResponse($data, 'Rekod Ditemui');
		}else{
			return $this->sendError('', 'Rekod Ditemui');
		}
	}
	public function getStreet($building_name)
	{
		$data = array();
        $coverage = Coverage::where('building_name',$building_name)->groupBy('street')->orderBy('street')->get();
		if(!empty($coverage)){
			foreach ($coverage as $key => $c) {
				array_push($data, array(
					'street' => $c->street,
				));
			}
			return $this->sendResponse($data, 'Rekod Ditemui');
		}else{
			return $this->sendError('', 'Rekod Ditemui');
		}
    }
}