<?php


namespace App\Core\Service;

use App\Core\Repository\PropertyGroup\PropertyGroupRepository;
use App\Core\Repository\PropertyGroupMapping\PropertyGroupMappingRepository;

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


class PropertyGroupMappingService
{
    private $propertyGroupRepository;
    private $propertyGroupMappingRepository;


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



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


            $data = $this->propertyGroupMappingRepository->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 getPropertyGroupMapping($propertyGroupMappingCriteria, $column = ['*'])
    {
        $response = ['status' => -1, 'message' => '', 'data' => null];

        try {

            $propertyGroupMapping =$this->select($propertyGroupMappingCriteria,$column);

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

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

        } 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);
    }


}
