2025-09-13 17:39:17 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
class Summary extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'content',
|
|
|
|
|
'key_insights',
|
|
|
|
|
'book_id',
|
2026-03-29 15:23:02 +03:00
|
|
|
'processing_status',
|
|
|
|
|
'processing_error',
|
|
|
|
|
'processed_at',
|
|
|
|
|
'model_used',
|
2025-09-13 17:39:17 +03:00
|
|
|
];
|
|
|
|
|
|
2026-03-29 15:23:02 +03:00
|
|
|
/**
|
|
|
|
|
* Get the attributes that should be cast.
|
|
|
|
|
*/
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'processed_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-13 17:39:17 +03:00
|
|
|
/**
|
|
|
|
|
* Get the book that owns the summary.
|
|
|
|
|
*/
|
|
|
|
|
public function book()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Book::class);
|
|
|
|
|
}
|
2026-03-29 15:23:02 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Scope a query to only include summaries with a specific status.
|
|
|
|
|
*/
|
|
|
|
|
public function scopeWithStatus($query, string $status)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('processing_status', $status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Scope a query to only include pending summaries.
|
|
|
|
|
*/
|
|
|
|
|
public function scopePending($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('processing_status', 'pending');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Scope a query to only include processing summaries.
|
|
|
|
|
*/
|
|
|
|
|
public function scopeProcessing($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('processing_status', 'processing');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Scope a query to only include completed summaries.
|
|
|
|
|
*/
|
|
|
|
|
public function scopeCompleted($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('processing_status', 'completed');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Scope a query to only include failed summaries.
|
|
|
|
|
*/
|
|
|
|
|
public function scopeFailed($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('processing_status', 'failed');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mark the summary as processing.
|
|
|
|
|
*/
|
|
|
|
|
public function markAsProcessing(): void
|
|
|
|
|
{
|
|
|
|
|
$this->update([
|
|
|
|
|
'processing_status' => 'processing',
|
|
|
|
|
'processing_error' => null,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mark the summary as completed.
|
|
|
|
|
*/
|
|
|
|
|
public function markAsCompleted(string $modelUsed): void
|
|
|
|
|
{
|
|
|
|
|
$this->update([
|
|
|
|
|
'processing_status' => 'completed',
|
|
|
|
|
'processing_error' => null,
|
|
|
|
|
'processed_at' => now(),
|
|
|
|
|
'model_used' => $modelUsed,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mark the summary as failed with an error message.
|
|
|
|
|
*/
|
|
|
|
|
public function markAsFailed(string $error): void
|
|
|
|
|
{
|
|
|
|
|
$this->update([
|
|
|
|
|
'processing_status' => 'failed',
|
|
|
|
|
'processing_error' => $error,
|
|
|
|
|
]);
|
|
|
|
|
}
|
2025-09-13 17:39:17 +03:00
|
|
|
}
|