<?php

namespace kernel\app_modules\tag\models;

use Illuminate\Database\Eloquent\Model;

/**
 * @property int $id
 * @property string $label
 * @property string $entity
 * @property int $entity_id
 * @property string $slug
 * @property int $status
 */
class Tag extends Model
{
    const DISABLE_STATUS = 0;
    const ACTIVE_STATUS = 1;

    protected $table = 'tag';

    protected $fillable = ['label', 'slug', 'status'];

    public static function labels(): array
    {
        return [
            'label' => 'Заголовок',
            'entity' => 'Сущность',
            'slug' => 'Slug',
            'status' => 'Статус',
        ];
    }

    /**
     * @return string[]
     */
    public static function getStatus(): array
    {
        return [
            self::DISABLE_STATUS => "Не активный",
            self::ACTIVE_STATUS => "Активный",
        ];
    }

    public static function getTagListByEntity(string $entity): array
    {
        return self::where("entity", $entity)->get()->toArray();
    }

    public static function getTagLabelByEntity(string $entity): array
    {
        $result = [];
        $tags = self::getTagListByEntity($entity);
        foreach ($tags as $tag){
            $result[$tag['id']] = $tag['label'];
        }

        return $result;
    }

}