<?php

namespace Modules\ProductCompat\Entities;

use Illuminate\Database\Eloquent\Model;

class PcJob extends Model
{
    protected $table = 'pc_jobs';

    protected $fillable = [
        'business_id', 'type', 'status', 'total', 'processed', 'matched',
        'added_parts', 'added_devices', 'added_barcodes', 'cursor', 'trigger',
        'message', 'started_at', 'finished_at',
    ];

    protected $casts = [
        'started_at'  => 'datetime',
        'finished_at' => 'datetime',
    ];

    public function percent(): int
    {
        return $this->total > 0 ? (int) floor($this->processed / $this->total * 100) : 0;
    }
}
