<?php

namespace App\Models;

use App\Models\Scopes\ParentBranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CustomerRiskProfile extends Model
{
    protected $fillable = [
        'customer_id',
        'risk_level',
        'score',
        'score_band',
        'score_version',
        'confidence',
        'thin_file',
        'manual_review_required',
        'last_trigger',
        'factors',
        'explanation',
        'calculated_at',
    ];

    protected function casts(): array
    {
        return [
            'score' => 'decimal:2',
            'confidence' => 'decimal:2',
            'thin_file' => 'boolean',
            'manual_review_required' => 'boolean',
            'factors' => 'array',
            'calculated_at' => 'datetime',
        ];
    }

    protected static function booted(): void
    {
        static::addGlobalScope(new ParentBranchScope('customers', 'customer_id'));
    }

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