<?php

namespace App\Models;

use App\Enums\WorkoutSource;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class WorkoutSessions extends Model
{
    use HasFactory, HasUlids;

    protected $fillable = [
        'user_id',
        'external_id',
        'source',
        'type',
        'title',
        'duration_seconds',
        'calories_burned',
        'distance_meters',
        'started_at',
    ];

    protected $attributes = [
        'source' => WorkoutSource::MANUAL->value,
    ];

    protected function casts(): array
    {
        return [
            'source' => WorkoutSource::class,
            'distance_meters' => 'integer',
            'started_at' => 'datetime',
        ];
    }

    /*
    |--------------------------------------------------------------------------
    | Relations
    |--------------------------------------------------------------------------
    */

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