<?php

namespace App\Models;

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

class RolePreset extends Model
{
    protected $fillable = ['name', 'description', 'permissions'];

    protected $casts = [
        'permissions' => 'array',
    ];

    public function users(): HasMany
    {
        return $this->hasMany(User::class, 'role_preset_id');
    }

    public static function defaultPermissions(): array
    {
        return [
            'individui' => 1,
            'gruppi' => 1,
            'eventi' => 1,
            'documenti' => 1,
            'mailing' => 1,
            'viste' => 1,
        ];
    }

    public static function adminPreset(): array
    {
        return [
            'individui' => 2,
            'gruppi' => 2,
            'eventi' => 2,
            'documenti' => 2,
            'mailing' => 2,
            'viste' => 2,
        ];
    }

    public static function operatorePreset(): array
    {
        return [
            'individui' => 2,
            'gruppi' => 2,
            'eventi' => 2,
            'documenti' => 1,
            'mailing' => 1,
            'viste' => 1,
        ];
    }

    public static function letturaPreset(): array
    {
        return [
            'individui' => 1,
            'gruppi' => 1,
            'eventi' => 1,
            'documenti' => 1,
            'mailing' => 1,
            'viste' => 1,
        ];
    }
}