<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
{{#morphableModels}}
use App\Models\{{.}};
{{/morphableModels}}

class {{modelName}} extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        {{#fillableFields}}
        '{{.}}',
        {{/fillableFields}}
        {{#isMorphable}}
        '{{morphName}}_id',
        '{{morphName}}_type',
        {{/isMorphable}}
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        {{#castFields}}
        '{{name}}' => '{{type}}',
        {{/castFields}}
    ];

    /**
     * Get the parent {{morphName}} model ({{#morphableModels}}{{.}}, {{/morphableModels}}).
     */
    public function {{morphName}}()
    {
        return $this->morphTo();
    }

    {{#hasMorphMany}}
    /**
     * Get all of the {{morphManyRelation}} for the {{modelName}}.
     */
    public function {{morphManyRelation}}()
    {
        return $this->morphMany({{morphManyModel}}::class, '{{morphManyName}}');
    }
    {{/hasMorphMany}}

    {{#otherRelations}}
    /**
     * Get the {{name}} associated with the {{../modelName}}.
     */
    public function {{name}}()
    {
        return $this->{{type}}({{relatedModel}}::class{{#hasAdditionalParams}}, {{additionalParams}}{{/hasAdditionalParams}});
    }
    {{/otherRelations}}
}