<?php

namespace App\Models;

use App\Enums\Prioriteit;
use App\Enums\ProjectRol;
use App\Enums\ProjectStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Project extends Model
{
    use SoftDeletes;

    protected $table = 'projects';

    protected $fillable = [
        'speerpunt_id',
        'naam',
        'beschrijving',
        'eigenaar_id',
        'status',
        'prioriteit',
        'startdatum',
        'streef_einddatum',
    ];

    protected function casts(): array
    {
        return [
            'status'          => ProjectStatus::class,
            'prioriteit'      => Prioriteit::class,
            'startdatum'      => 'date',
            'streef_einddatum' => 'date',
        ];
    }

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

    public function eigenaar(): BelongsTo
    {
        return $this->belongsTo(User::class, 'eigenaar_id');
    }

    public function teamleden(): BelongsToMany
    {
        return $this->belongsToMany(User::class, 'project_user')
            ->withPivot('rol')
            ->withTimestamps()
            ->using(ProjectUser::class);
    }

    public function fases(): HasMany
    {
        return $this->hasMany(Fase::class);
    }

    public function risicos(): HasMany
    {
        return $this->hasMany(Risico::class);
    }

    public function afhankelijkheden(): HasMany
    {
        return $this->hasMany(Afhankelijkheid::class);
    }

    public function afhankelijkVanMij(): HasMany
    {
        return $this->hasMany(Afhankelijkheid::class, 'afhankelijk_van_project_id');
    }

    public function besluiten(): HasMany
    {
        return $this->hasMany(Besluit::class);
    }

    public function commitments(): HasMany
    {
        return $this->hasMany(Commitment::class);
    }

    public function budgets(): HasMany
    {
        return $this->hasMany(Budget::class);
    }

    public function documents(): HasMany
    {
        return $this->hasMany(Document::class);
    }

    public function lessonsLearned(): HasMany
    {
        return $this->hasMany(LessonLearned::class);
    }

    public function overdrachtsplannen(): HasMany
    {
        return $this->hasMany(Overdrachtsplan::class);
    }

    public function metroLines(): HasMany
    {
        return $this->hasMany(MetroLine::class);
    }
}
