<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Spatie\Permission\Models\Permission;

class AddVetClinicPermissions extends Migration
{
    public function up()
    {
        $permissions = [
            'vet_clinic.access_module',
            'vet_clinic.manage_departments',
            'vet_clinic.manage_doctors',
            'vet_clinic.manage_pet_owners',
            'vet_clinic.manage_pets',
            'vet_clinic.view_appointments',
            'vet_clinic.manage_appointments',
            'vet_clinic.manage_prescriptions',
            'vet_clinic.manage_vaccinations',
            'vet_clinic.manage_medicines',
            'vet_clinic.manage_medical_conditions',
            'vet_clinic.view_reports',
            'vet_clinic.manage_reports',
            'vet_clinic.access_settings',
            'vet_clinic.superadmin',
        ];

        foreach ($permissions as $permission) {
            Permission::findOrCreate($permission, 'web');
        }
    }

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