<?php

namespace App\Master\Models;

use Mtc\Crm\Traits\ModelSortAndFilter;
use Database\Factories\Master\Models\BodyStyleTypeFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Mtc\MercuryDataModels\Traits\EnsuresSlug;
use Mtc\MercuryDataModels\Traits\OrderByName;
use Stancl\Tenancy\Database\Concerns\CentralConnection;

class BodyStyleType extends Model
{
    use CentralConnection;
    use HasFactory;
    use OrderByName;
    use ModelSortAndFilter;
    use EnsuresSlug;

    /**
     * Table name
     *
     * @var string
     */
    protected $table = 'body_styles';

    /**
     * Mass assign columns
     *
     * @var string[]
     */
    protected $fillable = [
        'name',
        'slug',
        'autotrader_id',
        'keyloop_id',
        'type',
        'do_not_sync',
    ];

    /**
     * Columns shown in JSON response by default
     *
     * @var string[]
     */
    protected $visible = [
        'id',
        'slug',
        'name',
        'type',
        'autotrader_id',
        'keyloop_id',
        'do_not_sync',
    ];

    protected $casts = [
        'do_not_sync' => 'boolean',
    ];

    #[\Override]
    protected static function boot()
    {
        parent::boot();

        self::saving(function (self $bodyStyleType) {
            $bodyStyleType->ensureSlug();
        });
    }

    /**
     * Model factory
     *
     * @return BodyStyleTypeFactory
     */
    protected static function newFactory()
    {
        return BodyStyleTypeFactory::new();
    }
}
