<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

class Currency extends Model
{
    use HasFactory;

    protected $fillable=['name','code','symbol','format','exchange_rate','precision','decimal_mark','thousands_separator','status'];
   
    protected static function booted()
    {
        static::created(function ($user) {
            static::removeFromCache();
        });
        static::updated(function ($user) {
            static::removeFromCache();
        });
        static::deleted(function ($user) {
            static::removeFromCache();
        });
    }

    public function scopeCode($query, $code){
        return $query->where('code',$code);
    }

    public static function removeFromCache()
    {
        Cache::forget('currencies');
    }

}
