<?php


namespace App\Http\Controllers\V1;

use App\Core\Service\PropertyRoomSizeTypeService;
use App\Exceptions\ApiErrorException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;

class PropertyRoomSizeTypeController
{


    private $propertyRoomSizeTypeService;


    public function __construct(PropertyRoomSizeTypeService $propertyRoomSizeTypeService)
    {
        $this->propertyRoomSizeTypeService = $propertyRoomSizeTypeService;

    }

    public function getPropertyRoomSizeTypes(){

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

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

            $propertyRoomSizeTypes = $this->propertyRoomSizeTypeService->select($propertyRoomSizeTypeCriteria, ['id', 'name', 'code', 'language_key']);


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

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

}
