<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class OrderItemFeature extends Model
{
    use HasFactory;

    protected $fillable = [
        'order_item_id',
        'feature_option_id',
        'price_at_time',
        'specifications',
    ];

    protected $casts = [
        'price_at_time' => 'decimal:2',
    ];

    public function orderItem()
    {
        return $this->belongsTo(OrderItem::class);
    }

    public function featureOption()
    {
        return $this->belongsTo(FeatureOption::class);
    }

    public function getFormattedPriceAttribute()
    {
        return number_format($this->price_at_time, 2);
    }
}
