<?php

namespace App\Models;
use App\Models\Zone;
use App\Models\RevenueStream;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\Contracts\Activity;
use Spatie\Activitylog\LogOptions;

class FinancebillDetails extends Model
{
	use HasFactory, LogsActivity;
	
	protected $table = 'financebilldetails';
	
	protected  $primaryKey = 'BillDetailID';
	
	protected $appends = ['zone_name','stream_name'];
	
	public $timestamps = false;
	
    protected $fillable = [
    'FinanceBillID',
	'StreamID',
	'ZoneID',
	'Amount',
	'Name',
	'Draft',
	'DraftID',
	'Status'
  ];
  
  public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
        ->logFillable()
		->logOnlyDirty(); //only the changed
    }
	
	public function tapActivity(Activity $activity)
    {
        $activity->table_name = "financebilldetails";
    }
  
  public function financebill(): BelongsTo
		{
			return $this->BelongsTo(FinanceBill::class,'FinanceBillID','FinanceBillID');
		}
	
	public function getZoneNameAttribute()
	{
		return Zone::where('ZoneID',$this->ZoneID)->pluck('ZoneName')->first();
	}
	
	public function getStreamNameAttribute()
	{
		return RevenueStream::where('StreamID',$this->StreamID)->pluck('StreamName')->first();
	}
  
}
