<?php

use Illuminate\Database\Migrations\Migration;
use Spatie\Permission\Models\Permission;

class AddWhatsAppPermissions extends Migration
{
    public function up()
    {
        foreach ($this->permissions() as $permission) {
            Permission::findOrCreate($permission, 'web');
        }
    }

    public function down()
    {
        foreach (Permission::where('name', 'LIKE', 'whatsapp.%')->get() as $permission) {
            $permission->delete();
        }
    }

    private function permissions(): array
    {
        return [
            'whatsapp.access_module',
            'whatsapp.manage_channels',
            'whatsapp.manage_templates',
            'whatsapp.view_messages',
            'whatsapp.send_messages',
            'whatsapp.access_settings',
        ];
    }
}
