<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Tier extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'slug',
        'description',
        'allowed_fields',
    ];

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

    public function filterFields(array $data): array
    {
        return collect($data)->only($this->allowed_fields ?? [])->all();
    }

    public function websites(): HasMany
    {
        return $this->hasMany(Website::class);
    }
}
