<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\ProductModel;

class Brand extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'name', 'slug', 'logo', 'website', 'description', 'status', 
        'created_by', 'updated_by'
    ];

    protected $casts = [
        'status' => 'boolean'
    ];

    /**
     * Get the products for the brand
     */
    public function products()
    {
        return $this->hasMany(Product::class);
    }

    /**
     * Get the models for the brand
     * গুরুত্বপূর্ণ: এখানে `App\Models\Model` ব্যবহার করতে হবে
     */
    public function models()
{
    return $this->hasMany(ProductModel::class);
}

    /**
     * Get the user who created this brand
     */
    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    /**
     * Get the user who last updated this brand
     */
    public function updater()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }

    /**
     * Scope a query to only include active brands
     */
    public function scopeActive($query)
    {
        return $query->where('status', true);
    }

    /**
     * Get the logo url attribute
     */
    public function getLogoUrlAttribute()
    {
        return $this->logo ? asset('storage/brands/' . $this->logo) : asset('images/no-image.png');
    }

    /**
     * Get the status badge attribute
     */
    public function getStatusBadgeAttribute()
    {
        return $this->status ? 
            '<span class="badge bg-success">Active</span>' : 
            '<span class="badge bg-danger">Inactive</span>';
    }
}