<?php

namespace App\Models;

use App\Constants\Status;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\Attribute;
use App\Traits\GlobalStatus;

class Category extends Model
{
    use GlobalStatus;

    public function subcategory()
    {
        return $this->hasOne(Subcategory::class);
    }

    public function featuredBadge(): Attribute
    {
        return new Attribute(function () {
            $html = '';
            if ($this->featured == Status::YES) {
                $html = '<span class="badge badge--primary">' . trans("Yes") . '</span>';
            } else {
                $html = '<span class="badge badge--dark">' . trans("No") . '</span>';
            }

            return $html;
        });
    }
}
