<?php

namespace Functional\Routines\Models;

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

/**
 * Pivot enrichi : un exercice positionné dans une routine, avec ses paramètres d'entraînement.
 *
 * @property int $position
 * @property int $sets
 * @property string $target_reps
 * @property int|null $rest_seconds
 * @property string|null $tempo
 * @property float|null $target_weight
 * @property string|null $notes
 */
#[UseFactory(RoutineExerciseFactory::class)]
class RoutineExercise extends Model
{
    use HasFactory;

    protected $fillable = [
        'routine_id', 'exercise_id', 'position', 'sets', 'target_reps',
        'rest_seconds', 'tempo', 'target_weight', 'notes',
    ];

    protected $casts = [
        'position' => 'integer',
        'sets' => 'integer',
        'rest_seconds' => 'integer',
        'target_weight' => 'decimal:2',
    ];

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

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