<?php 
namespace App\Models;

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

class Orders extends Model
{
    use HasFactory;

    protected $fillable = [
        'track_id',
        'user_id',
        'vendor_id',
        'items',
        'total_amount',
        'status',
        'payment_status',
        'delivery_address',
        'notes',
    ];

    protected $casts = [
        'items' => 'array',
    ];

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($order) {
            if (empty($order->track_id)) {
                $order->track_id = 'ORD_' . strtoupper(Str::random(6));
            }
        });
    }

}
