<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CarMake extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'status',
        'created_by',
    ];

    protected $casts = [
        'status' => 'string',
    ];

    /**
     * Relationships
     */
    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function models()
    {
        return $this->hasMany(CarModel::class, 'make_id');
    }

    public function products()
    {
        return $this->hasMany(Product::class, 'make_id');
    }

    /**
     * Scope for active makes
     */
    public function scopeActive($query)
    {
        return $query->where('status', 'active');
    }
}