<?php


namespace App\Http\Controllers\V1;


use App\Core\Service\CurrencyService;
use App\Exceptions\ApiErrorException;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Log;

class CurrencyController extends Controller
{

    private $currencyService;


    public function __construct(
        CurrencyService $currencyService
    ){
        $this->currencyService = $currencyService;
    }
    public function getListCurrency(){

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

            $currencyList = $this->currencyService->getCurrencyList();

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

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

    }
}

