<?php

namespace App\Models;

use App\Traits\HasJsonTranslations;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Team extends Model
{
    /** @use HasFactory<\Database\Factories\TeamFactory> */
    use HasFactory, HasJsonTranslations;
    
    protected $fillable = [
        'name',
        'job_title',
        'img',
        'status',
        'show_in_home',
        'order'
    ];

    protected $casts = [
        'name' => 'array',
        'job_title' => 'array',
    ];

    public function getImgAttribute()
    {
        return $this->attributes['img'] ? asset('storage/teams/' . $this->attributes['img']) : asset('assets/dashboard/images/noimage.png');
    }

    public function getNameAttribute()
    {
        return $this->getTranslation('name');
    }

    public function getJobTitleAttribute()
    {
        return $this->getTranslation('job_title');
    }

    public function scopeActive($query)
    {
        return $query->where('status', 1);
    }

    public function scopeHome($query)
    {
        return $query->where('show_in_home', true);
    }
}

