from rest_framework import serializers
from workouts.models import (
    Exercise,
    WorkoutImport,
    WorkoutRoutine,
    WorkoutRoutineExercise,
)


class ExerciseSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Exercise
        fields = "__all__"


class WorkoutRoutineExerciseSerializer(serializers.ModelSerializer):
    exercise_name = serializers.CharField(source="exercise.name", read_only=True)

    class Meta:
        model = WorkoutRoutineExercise
        fields = [
            "id",
            "exercise",
            "exercise_name",
            "sequence",
            "target_sets",
            "target_reps",
            "target_weight_kg",
            "enabled",
        ]


class WorkoutRoutineSerializer(serializers.HyperlinkedModelSerializer):
    routine_exercises = WorkoutRoutineExerciseSerializer(many=True, read_only=True)

    class Meta:
        model = WorkoutRoutine
        fields = "__all__"


class WorkoutImportSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = WorkoutImport
        fields = "__all__"
        read_only_fields = (
            "uuid",
            "processing_started",
            "processed_finished",
            "process_log",
            "process_count",
            "error_log",
            "file_hash",
        )
