<?php

namespace Functional\Tracking\Models;

use Functional\Exercises\Models\Exercise;
use Functional\Tracking\Database\Factories\SetLogFactory;
use Illuminate\Database\Eloquent\Attributes\UseFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Une série loggée au sein d'une séance, pour un exercice donné.
 */
#[UseFactory(SetLogFactory::class)]
class SetLog extends Model
{
    use HasFactory;

    protected $fillable = [
        'workout_session_id', 'exercise_id', 'set_number', 'reps', 'weight', 'rpe',
        'duration_seconds', 'distance_meters', 'is_warmup', 'is_completed', 'logged_at',
    ];

    protected $casts = [
        'set_number' => 'integer',
        'reps' => 'integer',
        'weight' => 'decimal:2',
        'rpe' => 'decimal:1',
        'duration_seconds' => 'integer',
        'distance_meters' => 'decimal:2',
        'is_warmup' => 'boolean',
        'is_completed' => 'boolean',
        'logged_at' => 'datetime',
    ];

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

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