<?php

namespace App\Models;

use App\Models\Concerns\BelongsToUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Caution extends Model
{
    use BelongsToUser, HasFactory, SoftDeletes;

    protected $guarded = [];

    protected $casts = [
        'date_depot' => 'date',
        'date_restitution' => 'date',
        'montant' => 'decimal:0',
    ];

    public const STATUT_ACTIVE = 'active';
    public const STATUT_RESTITUEE = 'remboursée';
    public const STATUT_ANNULEE = 'annulée';
    public const STATUT_DETTE = 'endeté';
    const STATUT_PARTIEL = 'partiellement utilisée';
    const STATUT_EPUISE = 'solde epuisé';


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

    public function isActive(): bool
    {
        return $this->statut === self::STATUT_ACTIVE;
    }
}
