<?php

namespace App\Modules\Bookings;

use Illuminate\Support\Facades\Auth;
use App\Models\ValidationModel;
use App\Modules\Bookings\Manufacturer;

class ModelNumber extends ValidationModel
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'model_numbers';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['manufacturer_id', 'model_number'];

    /**
     * Array of validation rules.
     *
     * @var  array
     */
    protected static $rules = [
        'manufacturer_id' => 'required',
        'model_number'    => 'required',
    ];

    /**
     * The "booting" method of the model.
     *
     * @return void
     */
    public static function boot()
    {
        parent::boot();

        // When a transaction is created we want to
        // update the created_by field
        static::creating(function ($model) {
            $model->created_by = Auth::user()->id;
        });
    }

    /**
     * The manufacturer for this model.
     *
     * @return \App\Modules\Bookings\Manufacturer
     */
    public function manufacturer()
    {
        return $this->belongsTo(Manufacturer::class, 'manufacturer_id');
    }
}
