<?php

namespace Functional\Streaks\Models;

use Functional\Streaks\Database\Factories\StreakDayFactory;
use Functional\Streaks\Enums\StreakDaySource;
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;

/**
 * Un jour d'activité compté pour le streak (séance réelle, saisie manuelle, freeze ou repos planifié).
 * Unique par (user, date) : au plus un jour par user et par date.
 *
 * @property int $user_id
 * @property \Illuminate\Support\Carbon $date
 * @property StreakDaySource $source
 * @property int|null $workout_session_id
 */
#[UseFactory(StreakDayFactory::class)]
class StreakDay extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id', 'date', 'source', 'workout_session_id',
    ];

    protected $casts = [
        'date' => 'date',
        'source' => StreakDaySource::class,
    ];

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