<?php


namespace App\Core\Service;

use App\Core\Repository\PropertyBookingPaymentType\PropertyBookingPaymentTypeRepository;


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


class PropertyBookingPaymentTypeService
{
    private $propertyBookingPaymentTypeRepository;


    public function __construct
    (
        Request $request,
        PropertyBookingPaymentTypeRepository $propertyBookingPaymentTypeRepository
    )
    {
        $this->request = $request;
        $this->propertyBookingPaymentTypeRepository = $propertyBookingPaymentTypeRepository;

    }


    public function select($param = [], $column = ['*'])
    {
        $response = ['status' => -1, 'message' => '', 'data' => null];
        try {
            $data = $this->propertyBookingPaymentTypeRepository->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 getPropertyBookingPaymentTypeList(){

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

            $propertyBookingPaymentTypeListRequest = [
                'criteria' => [
                    ['field' => 'status', 'condition' => '=', 'value' => 1]
                ]
            ];

            $propertyBookingPaymentTypeList = $this->select($propertyBookingPaymentTypeListRequest, ['id', 'name', 'language_key', 'code']);

            if(isset($propertyBookingPaymentTypeList['data'])){
                $return['booking_payment_types'] = $propertyBookingPaymentTypeList['data'] ;
            }

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

}
