<?php

namespace Functional\Streaks\Models;

use Functional\Streaks\Database\Factories\StreakFactory;
use Functional\Users\Models\User;
use Illuminate\Database\Eloquent\Attributes\UseFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Streak courant d'un utilisateur (une ligne par user) : régularité d'entraînement, gamification.
 *
 * @property int $user_id
 * @property int $current_count
 * @property int $longest_count
 * @property \Illuminate\Support\Carbon|null $last_active_date
 * @property int $freezes_available
 * @property \Illuminate\Support\Carbon|null $freeze_last_granted_on
 */
#[UseFactory(StreakFactory::class)]
class Streak extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id', 'current_count', 'longest_count', 'last_active_date',
        'freezes_available', 'freeze_last_granted_on', 'last_reminded_on',
    ];

    protected $casts = [
        'current_count' => 'integer',
        'longest_count' => 'integer',
        'last_active_date' => 'date',
        'freezes_available' => 'integer',
        'freeze_last_granted_on' => 'date',
        'last_reminded_on' => 'date',
    ];

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