<?php

namespace App\Http\Controllers\V1;

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

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

class PropertyRoomViewTypeController
{


    private $propertyRoomViewTypeService;


    public function __construct(
        PropertyRoomViewTypeService $propertyRoomViewTypeService
    )
    {
        $this->propertyRoomViewTypeService = $propertyRoomViewTypeService;
    }



    public function getPropertyRoomViewTypeList()
    {
        $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
        try {

            $propertyRoomViewTypeCriteria = [
                'criteria' => [
                    ['field' => 'status', 'condition' => '=', 'value' => 1]
                ],
                "orderBy" => [
                    ["field" => "name", "value" => "ASC"]
                ]
            ];

            $propertyRoomViewTypeList = $this->propertyRoomViewTypeService->getPropertyRoomViewTypes($propertyRoomViewTypeCriteria);

            if($propertyRoomViewTypeList['status'] != 'success'){
                throw new ApiErrorException($propertyRoomViewTypeList['message']);
            }

            $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $propertyRoomViewTypeList['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']);


    }

}
