<?php


namespace App\Core\Service;

use App\Core\Repository\PropertyGroup\PropertyGroupRepository;

use Illuminate\Http\Request;
use App;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Config;
use Exception;
use App\Exceptions\ApiErrorException;


class PropertyGroupService
{
    private $propertyGroupRepository;


    public function __construct
    (
        Request $request,
        PropertyGroupRepository $propertyGroupRepository
    )
    {
        $this->request = $request;
        $this->propertyGroupRepository = $propertyGroupRepository;
    }



    public function select($param = [], $column = ['*'])
    {
        $response = ['status' => -1, 'message' => '', 'data' => null];
        try {


            $data = $this->propertyGroupRepository->findByCriteria($param, $column);
            $response['status'] = 1;
            $response['data'] = $data;


        } catch (ApiErrorException $e) {
            $response['status'] = 0;
            $response['message'] = $e->getMessage();
        } catch (Exception $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error($message);
            $response['message'] = $e->getMessage();
        }

        return output($response);
    }


    public function getPropertyGroup($propertyGroupCriteria, $column = ['*'])
    {
        $response = ['status' => -1, 'message' => '', 'data' => null];

        try {

            $propertyGroup =$this->select($propertyGroupCriteria,$column);

            if(!$propertyGroup){
                throw new ApiErrorException(lang('Property Group data not found'));
            }

            $response['status'] = 1;
            $response['data'] = $propertyGroup;

        } catch (ApiErrorException $e) {
            $response['status'] = 0;
            $response['message'] = implode(', ', $e->getMessageArr());
        } catch (Exception $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error($message);
            $response['message'] = $e->getMessage();
        }
        return output($response);
    }

}
