<?php

namespace App\Modules\Bookings;

use App\Models\ValidationModel;
use App\Modules\Bookings\TemplateItem;
use App\Modules\Bookings\TaskType;

class Template extends ValidationModel
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name', 'priority'];

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'templates';

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

    /**
     * Returns all the template items.
     *
     * @return App\Modules\Bookings\TemplateItem
     */
    public function items()
    {
        return $this->hasMany(TemplateItem::class, 'template_id');
    }

    /**
     * Get the template task types.
     *
     * @return collection
     */
    public function taskTypes()
    {
        return $this->belongsToMany(TaskType::class, 'template_task_types');
    }
}
