<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class GroupPost extends Model
{
    use HasFactory;
    use SoftDeletes;

    public const TYPE_ANNOUNCEMENT = 'announcement';
    public const TYPE_RELEASE = 'release';
    public const TYPE_RECRUITMENT = 'recruitment';
    public const TYPE_UPDATE = 'update';

    public const STATUS_DRAFT = 'draft';
    public const STATUS_PUBLISHED = 'published';
    public const STATUS_ARCHIVED = 'archived';

    protected $fillable = [
        'group_id',
        'author_user_id',
        'type',
        'title',
        'slug',
        'excerpt',
        'content',
        'cover_path',
        'status',
        'is_pinned',
        'published_at',
    ];

    protected $casts = [
        'is_pinned' => 'boolean',
        'published_at' => 'datetime',
    ];

    public function getRouteKeyName(): string
    {
        return 'slug';
    }

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

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