<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Traits\Searchable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use App\Constants\Status;

class NoticeBoard extends Model
{
    use HasFactory, Searchable;

    protected $guarded = [];

    protected $casts = [
        'published_at' => 'date'
    ];

    protected function statusBadge(): Attribute
    {
        return Attribute::make(function () {
            $html = '';
            switch ($this->status) {
                case Status::Draft:
                    $html = '<span class="badge badge--warning">' . trans('Draft') . '</span>';
                    break;
                case Status::Published:
                    $html = '<span><span class="badge badge--success">' . trans('Published') . '</span></span>';
                    break;
                case Status::Inactive:
                    $html = '<span><span class="badge badge--danger">' . trans('Inactive') . '</span></span>';
                    break;
            }
            return $html;
        });
    }
}
