<?php

namespace App\Models\Tenant;

use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;

/**
 * Append-only audit log: every PricingEngine::quote() call writes one row
 * here so we can reconstruct "why was this part priced at 218 lei?" later.
 */
class PricingApplicationLog extends Model
{
    use BelongsToTenant;

    public $timestamps = false;

    protected $fillable = [
        'company_id', 'subject_type', 'subject_id', 'part_id', 'vehicle_id', 'client_id',
        'base_price', 'final_price', 'applied_coefficients', 'context', 'calculated_at',
    ];

    protected $casts = [
        'base_price' => 'decimal:2',
        'final_price' => 'decimal:2',
        'applied_coefficients' => 'array',
        'context' => 'array',
        'calculated_at' => 'datetime',
    ];

    public function subject(): MorphTo { return $this->morphTo(); }
    public function part(): BelongsTo { return $this->belongsTo(Part::class); }
    public function vehicle(): BelongsTo { return $this->belongsTo(Vehicle::class); }
    public function client(): BelongsTo { return $this->belongsTo(Client::class); }
}
