<?php

namespace Modules\PurchaseRequisition\Entities;

use Illuminate\Database\Eloquent\Model;

class PrCurrency extends Model
{
    protected $table = 'pr_currencies';

    protected $guarded = ['id'];

    protected $casts = [
        'conversion_rate_to_egp' => 'decimal:4',
        'is_active' => 'boolean',
    ];

    /**
     * Get the business that owns this currency.
     */
    public function business()
    {
        return $this->belongsTo(\App\Business::class);
    }

    /**
     * Get supplier responses using this currency.
     */
    public function supplierResponses()
    {
        return $this->hasMany(PrSupplierResponse::class, 'currency_id');
    }

    /**
     * Scope to filter active currencies.
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    /**
     * Scope to filter by business.
     */
    public function scopeForBusiness($query, $businessId)
    {
        return $query->where('business_id', $businessId);
    }

    /**
     * Convert amount to EGP.
     */
    public function convertToEgp($amount)
    {
        return $amount * $this->conversion_rate_to_egp;
    }
}
