<?php

namespace App\Models;

use App\Enums\AnnouncementType;
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\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Swindon\FilamentHashids\Traits\HasHashid;

class Announcement extends Model
{
    use HasFactory, HasHashid, SoftDeletes;

    protected $guarded = ['id'];

    protected function casts(): array
    {
        return [
            'type' => AnnouncementType::class,
        ];
    }

    #[Scope]
    protected function public(Builder $query): void
    {
        $query->where('type', AnnouncementType::PUBLIC);
    }

    #[Scope]
    protected function company(Builder $query): void
    {
        $query->where('type', AnnouncementType::COMPANY);
    }

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

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