<?php

namespace App\Http\Resources\Market\Coingecko;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Cache;

class TickerCoingecko extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        self::withoutWrapping();

        return [
            'ticker_id' => $this->baseCurrency->symbol . '_' . $this->quoteCurrency->symbol,
            'base_currency' => $this->baseCurrency->symbol,
            'target_currency' =>  $this->quoteCurrency->symbol,
            'last_price' => math_formatter(market_get_stats($this->id, 'last'), $this->quote_precision),
            'base_volume' => math_formatter(market_get_stats($this->id, 'volume'), $this->base_precision),
            'target_volume' => math_formatter(market_get_stats($this->id, 'volumeQuote'), $this->quote_precision),
            'bid' => math_formatter(market_get_stats($this->id, 'bid'), $this->quote_precision),
            'ask' => math_formatter(market_get_stats($this->id, 'ask'), $this->quote_precision),
            'high' => math_formatter(market_get_stats($this->id, 'high'), $this->quote_precision),
            'low' => math_formatter(market_get_stats($this->id, 'low'), $this->quote_precision),
        ];
    }
}
