<?php

namespace App\Models;

use App\Enums\VerificationStatus;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Swindon\FilamentHashids\Traits\HasHashid;

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

    protected $guarded = ['id'];

    protected function casts(): array
    {
        return [
            'partner_media_id' => 'integer',
        ];
    }

    #[Scope]
    public function pending(Builder $query): void
    {
        $query->where('status', VerificationStatus::PENDING);
    }

    public static function dataChangeEntryLabels(): array
    {
        return [
            'name' => 'Nama',
            'email' => 'Alamat Surel',
            'phone_number' => 'Nomor Telepon',
            'press_card' => 'No. Kartu Pers',
            'press_card_docs' => 'Dokumen Kartu Pers',
            'ukw_certificate' => 'No. Sertifikat UKW',
            'ukw_certificate_docs' => 'Dokumen Sertifikat UKW',
        ];
    }

    public function dataChangeRequests(): MorphMany
    {
        return $this->morphMany(DataChangeRequest::class, 'entity');
    }

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