<?php

namespace App\Models;

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

class PackageItem extends Model
{
    use HasFactory;

    protected $fillable = [
        'package_id', 'status', 'target_json', 'payload_json', 'attempts', 'last_error', 'result_json', 'provider_message_id', 'cost', 'currency', 'idempotency_key',
    ];

    protected function casts(): array
    {
        return [
            'target_json' => 'array',
            'payload_json' => 'array',
            'result_json' => 'array',
            'attempts' => 'integer',
            'cost' => 'decimal:4',
        ];
    }

    public function package()
    {
        return $this->belongsTo(Package::class);
    }
}
