<?php

namespace App\Models;

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

class ClientHealthScore extends Model
{
    use HasFactory;

    protected $fillable = [
        'client_id',
        'score_date',
        'score',
        'status',
        'readiness',
        'api_score',
        'data_quality_score',
        'report_score',
        'mail_score',
        'alert_score',
        'task_score',
        'onboarding_score',
        'breakdown',
        'risk_items',
        'recommendations',
        'calculated_at',
    ];

    protected $casts = [
        'score_date' => 'date',
        'score' => 'integer',
        'api_score' => 'integer',
        'data_quality_score' => 'integer',
        'report_score' => 'integer',
        'mail_score' => 'integer',
        'alert_score' => 'integer',
        'task_score' => 'integer',
        'onboarding_score' => 'integer',
        'breakdown' => 'array',
        'risk_items' => 'array',
        'recommendations' => 'array',
        'calculated_at' => 'datetime',
    ];

    public function client(): BelongsTo
    {
        return $this->belongsTo(Client::class);
    }

    public function statusLabel(): string
    {
        return match ($this->status) {
            'excellent' => 'Çok İyi',
            'healthy' => 'Sağlıklı',
            'watch' => 'Takip Gerekli',
            'risk' => 'Riskli',
            'critical' => 'Kritik',
            default => ucfirst((string) $this->status),
        };
    }

    public function badgeClass(): string
    {
        return match ($this->status) {
            'excellent' => 'badge-success',
            'healthy' => 'badge-info',
            'watch' => 'badge-warning',
            'risk' => 'badge-danger',
            'critical' => 'badge-dark',
            default => 'badge-secondary',
        };
    }
}
