<?php

namespace App\Core\Service\PropertyPhotoService;

use App\Core\Repository\PropertyPhotoCategory\PropertyPhotoCategoryRepository;


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

class PropertyPhotoCategoryService
{

   private $propertyPhotoCategoryRepository;


    public function __construct(
        PropertyPhotoCategoryRepository $propertyPhotoCategoryRepository
    )
    {
        $this->propertyPhotoCategoryRepository = $propertyPhotoCategoryRepository;

    }



    public function select($param = [], $column = ['*'])
    {

        $response = ['status' => -1, 'message' => '', 'data' => null];

        try {

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

        } catch (ApiErrorException $e) {
            $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 getPropertyPhotoCategoryList($params){

        $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
        try {
            $return = [];

            // get all photo category types
            $photoCategoryRequest = [
              'with' => []
            ];
            $photoCategoryResponse = $this->select($photoCategoryRequest);

            if($photoCategoryResponse['status'] == false){
                throw new ApiErrorException(lang('Category Data Not Loaded'));
            }
            $photoCategoryCollection = collect($photoCategoryResponse['data']);
            foreach ($photoCategoryCollection as $photoCategory){



                // Get Locale data
                $nameLocale = [];


                $photoCategoryItem['id'] = $photoCategory['id'];
                $photoCategoryItem['category_name'] =  $photoCategory['category_name'];

                $return[] = $photoCategoryItem ;
            }

            $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => ['photo_category_list' => $return]];

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

        return output($response);
    }




}
