<?php

namespace App\Models;

use Database\Factories\ResumeReportFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ResumeReport extends Model
{
    /** @use HasFactory<ResumeReportFactory> */
    use HasFactory;

    public const STATUS_PENDING = 'pending';

    public const STATUS_PROCESSING = 'processing';

    public const STATUS_COMPLETED = 'completed';

    public const STATUS_FAILED = 'failed';

    /**
     * The attributes that are mass assignable.
     *
     * @var list<string>
     */
    protected $fillable = [
        'user_id',
        'is_current',
        'original_filename',
        'disk',
        'path',
        'mime_type',
        'size_bytes',
        'status',
        'ats_score',
        'remote_readiness_score',
        'extracted_skills',
        'role_suggestions',
        'missing_keywords',
        'resume_improvements',
        'analysis',
        'failure_reason',
        'analyzed_at',
    ];

    /**
     * @return BelongsTo<User, $this>
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function isCompleted(): bool
    {
        return $this->status === self::STATUS_COMPLETED && $this->analyzed_at !== null;
    }

    public function hasFailed(): bool
    {
        return $this->status === self::STATUS_FAILED;
    }

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'size_bytes' => 'integer',
            'is_current' => 'boolean',
            'ats_score' => 'integer',
            'remote_readiness_score' => 'integer',
            'extracted_skills' => 'array',
            'role_suggestions' => 'array',
            'missing_keywords' => 'array',
            'resume_improvements' => 'array',
            'analysis' => 'array',
            'analyzed_at' => 'datetime',
        ];
    }
}
