<?php

namespace App\Domain\Website\Models;

use App\Domain\Shared\Traits\BelongsToAcademy;
use App\Domain\Shared\Traits\HasUuid;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\SoftDeletes;

class WebsiteNews extends Model
{
    use BelongsToAcademy, HasUuid, SoftDeletes;

    protected $table = 'website_news';

    protected $fillable = [
        'academy_id',
        'title',
        'title_en',
        'slug',
        'body',
        'body_en',
        'excerpt',
        'excerpt_en',
        'category',
        'category_en',
        'published_at',
        'is_featured',
        'sort_order',
        'created_by',
    ];

    protected $casts = [
        'published_at' => 'datetime',
        'is_featured' => 'boolean',
        'sort_order' => 'integer',
    ];

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

    public function image(): MorphOne
    {
        return $this->morphOne(Media::class, 'mediable')
            ->where('collection', 'news_image');
    }
}
