<?php

namespace App\Models;

use App\Traits\ApiQuery;
use App\Traits\GlobalStatus;
use Illuminate\Database\Eloquent\Model;

class TicketStatus extends Model
{
    use ApiQuery, GlobalStatus;

    protected $casts = [
        'converted_color' => 'object',
    ];

    public function supportTickets()
    {
        return $this->hasMany(SupportTicket::class)->primary();
    }

    public function pendingSupportTickets()
    {
        return $this->hasMany(SupportTicket::class)->pending();
    }

    public function getStatusBadgeAttribute()
    {
        $hsl = $this->converted_color;

        if (!isset($hsl->h, $hsl->s, $hsl->l)) {
            return '--';
        }

        $hslString  = "{$hsl->h} {$hsl->s}% {$hsl->l}%";
        $statusName = e(__($this->name));

        return '<span class="badge regularView statusName" style="--badge-color: ' . $hslString . ';">' . $statusName . '</span>';
    }

    public function admin()
    {
        return $this->belongsTo(Admin::class);
    }

}
