<?php

namespace App\Models;

use App\Enums\AthleteLevel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class AthleteAssessment extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'athlete_id',
        'coach_id',
        'assessment_date',
        'weight_kg',
        'height_cm',
        'bmi',
        'body_fat_percentage',
        'athlete_level',
        'training_history',
        'goal_id',
        'coach_notes',
        'is_initial',
        'created_by',
    ];

    protected function casts(): array
    {
        return [
            'assessment_date' => 'date',
            'athlete_level' => AthleteLevel::class,
            'is_initial' => 'boolean',
        ];
    }

    public function athlete()
    {
        return $this->belongsTo(Athlete::class);
    }

    public function coach()
    {
        return $this->belongsTo(Coach::class);
    }

    public function goal()
    {
        return $this->belongsTo(Goal::class);
    }

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function measurements()
    {
        return $this->hasOne(BodyMeasurement::class, 'assessment_id');
    }

    public function lifestyle()
    {
        return $this->hasOne(LifestyleRecord::class, 'assessment_id');
    }

    public function medical()
    {
        return $this->hasOne(MedicalRecord::class, 'assessment_id');
    }

    public function photos()
    {
        return $this->hasMany(BodyPhoto::class, 'assessment_id');
    }
}
