<?php

namespace App\Models;

use App\Enums\MediaClassification;
use App\Enums\MediaType;
use App\Enums\VerificationStatus;
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\MorphOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class PartnerMedia extends Model implements HasMedia
{
    use HasFactory, InteractsWithMedia, SoftDeletes;

    protected $guarded = ['id'];

    protected function casts(): array
    {
        return [
            'type' => MediaType::class,
            'classification' => MediaClassification::class,
            'status' => VerificationStatus::class,
        ];
    }

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

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

    public function announcements(): BelongsToMany
    {
        return $this->belongsToMany(Announcement::class, 'announcement_media');
    }

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

    public function taskAssignments(): BelongsToMany
    {
        return $this->belongsToMany(TaskAssignment::class, 'task_assignment_media')
            ->withPivot(['status'])
            ->withTimestamps();
    }

    public function cooperations(): BelongsToMany
    {
        return $this->belongsToMany(Cooperation::class, 'cooperation_media')
            ->withPivot(['status'])
            ->withTimestamps();
    }

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

    public function verificationRequest(): MorphOne
    {
        return $this->morphOne(VerificationRequest::class, 'verifiable');
    }
}
