<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class MacroCollection extends Model
{
    protected $fillable = [
        'uuid',
        'name',
        'last_imported_at',
    ];

    protected function casts(): array
    {
        return [
            'last_imported_at' => 'datetime',
        ];
    }

    public function macros(): BelongsToMany
    {
        return $this->belongsToMany(Macro::class, 'macro_collection_macros')
            ->withPivot('order')
            ->orderBy('macro_collection_macros.order');
    }
}
