<?php

namespace App\Http\Controllers\V1;

use App\Http\Controllers\Controller;
use App\Core\Service\PropertyChannelCategoryService;
use Illuminate\Http\Request;

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

class PropertyChannelCategoryController
{


    private $request;
    private $propertyChannelCategoryService;


    public function __construct(
        Request $request,
        PropertyChannelCategoryService $propertyChannelCategoryService
    )
    {
        $this->request = $request;
        $this->propertyChannelCategoryService = $propertyChannelCategoryService;

    }



    public function getPropertyChannelCategories(Request $request)
    {

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

            if (is_null($this->request->getContent())) {
                throw new ApiErrorException(lang('Parameter Error.'));
            }

            $params = $this->request->params;

            $requestParams = [
                'locale' => fillOnUndefined($params, 'locale'),
            ];

            $propertyChannelCategory = $this->propertyChannelCategoryService->getPropertyChannelCategories($requestParams);
            if($propertyChannelCategory['status'] != 'success'){
                throw new ApiErrorException($propertyChannelCategory['message']);
            }

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

        } 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 apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);


    }



}