<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
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\Relations\MorphMany;

class TaskAssignment extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    protected function casts(): array
    {
        return [
            'start_date' => 'date',
            'end_date' => 'date',
        ];
    }

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

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

    public function rejectionReasons(): MorphMany
    {
        return $this->morphMany(RejectionReason::class, 'rejectable');
    }

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

    public function partnerMedia(): BelongsToMany
    {
        return $this->belongsToMany(PartnerMedia::class, 'media_task_assignment')
            ->withPivot(['status'])
            ->withTimestamps();
    }
}
