<?php

namespace App;

use App\Repositories\TrainingWorkoutSectionRepository;
use Illuminate\Database\Eloquent\Model;

class TrainingWorkoutSection extends Model
{
    protected $fillable = [
        "training_workout_id","description", "seconds", "rounds", "type", "custom_score", "custom_score_explanation"
    ];

    protected $with = ["lines"];

    protected $hidden = ["pivot"];

    protected $appends = [
        "scoring"
    ];

    public function getScoringAttribute() {
        $type = $this->type;
        if ($type=='AMRAP') {
            return [
                "rounds" => true,
                "reps" => true,
                "completed" => false,
                "time" => false,
            ];
        } else if ($type=='Death By') {
            return [
                "rounds" => true,
                "reps" => false,
                "completed" => false,
                "time" => false,
            ];
        } else if ($type=='For Time' || $type=='Chipper') {
            return [
                "rounds" => false,
                "reps" => false,
                "completed" => ($this->seconds!=null) ? true : false,
                "time" => true,
            ];
        } else if ($type=='EMOM' || $type=='E2MOM') {
            return [
                "rounds" => false,
                "reps" => false,
                "completed" => true,
                "time" => false,
            ];
        } else {
            return [
                "rounds" => true,
                "reps" => true,
                "completed" => true,
                "time" => true,
            ];
        }
    }

    public function workouts(){
        return $this->belongsTo("App\TrainingWorkout");
    }

    public function lines(){
        return $this->hasMany("App\TrainingWorkoutLine");
    }
}
