<?php

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;


class PermissionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $permissions = [
            /**
             * The USER specific permissions
             */
            "user.create" => "Creation of new user",
            "user.list" => "Access to list the users.",
            "user.show" => "Shows another user profile.",
            "user.edit" => "Allows editing of other users.",
            "user.delete" => "Allows deleting of other users.",
            "ownuser.edit" => "Allows editing of your own user",

            /**
             * The CALENDAR specific permissions //TODO: Do we use them?
             */
            "calendar.create" => "Create a new event.",
            "calendar.list" => "Shows all events.",
            "calendar.show" => "Shows a specific event.",
            "calendar.edit" => "Allows editing of events.",
            "calendar.delete" => "Allows the deletion of events.",

            /**
             * The EXTERNAL LINK specific permissions
             */
            "link.external.create" => "Create a new external link.",
            "link.external.list" => "List all external links.",
            "link.external.show" => "Show a specific external link",
            "link.external.edit" => "Allows editing of external links.",
            "link.external.delete" => "Allows deletion of external links",

            /**
             * The EVENT specific permissions
             */
            "event.create" => "Create a new event",
            "event.list" => "Shows all events",
            "event.show" => "Shows a specific event",
            "event.edit" => "Allows editing of events",
            "event.delete" => "Allows deletion of events",

            /**
             * The CONTACT specific permissions
             */
            "contact.create" => "Creates a new contact",
            "contact.list" => "Shows all contacts",
            "contact.show" => "Shows a specific contact",
            "contact.edit" => "allows editing of contacts",
            "contact.delete" => "Allows deletion of contacts",

            /**
             * The FEEDBACK specific permissions
             */
            "feedback.create" => "Creates a new feedback message",
            "feedback.list" => "Shows all feedback messages",
            "feedback.show" => "Shows a specific feedback message",
            "feedback.edit" => "allows editing of feedback messages",
            "feedback.delete" => "allows deletion of feedback messages",

            /**
             * The MENUPLAN specific permissions
             */
            "menuplan.create" => "Create a new menuplan",
            "menuplan.list" => "Shows all menuplans",
            "menuplan.show" => "Shows a specific menuplan",
            "menuplan.edit" => "Allows editing of menuplans",
            "menuplan.delete" => "Allows deletion of menuplans",

            /**
             * The RESOURCE CATEGORY specific permissions
             */
            "resource.category.create" => "Create a new resource category",
            "resource.category.list" => "Shows all resource categories",
            "resource.category.show" => "Shows a specific resource category",
            "resource.category.edit" => "Allows editing of resource categories",
            "resource.category.delete" => "Allows deletion of resource categories",

            /**
             * The RESOURCE EXTENSION specific permissions
             */
            "resource.extension.create" => "Create a new resource extension",
            "resource.extension.list" => "Shows all resource extensions",
            "resource.extension.show" => "Shows a specific resource extension",
            "resource.extension.edit" => "Allows editing of resource extensions",
            "resource.extension.delete" => "Allows deletion of resource extensions",

            /**
             * The RESOURCE specific permissions
             */
            "resource.create" => "Create a new resource",
            "resource.list" => "Shows all resources",
            "resource.show" => "Shows a specific resource",
            "resource.edit" => "Allows editing of resources",
            "resource.delete" => "Allows deletion of resources",

            /**
             * The WASHING MACHINE specific permissions
             */
            "washing.machine.create" => "Create a new washing machine",
            "washing.machine.list" => "Shows all washing machines",
            "washing.machine.show" => "Shows a specific washing machine",
            "washing.machine.edit" => "Allows editing of washing machines",
            "washing.machine.delete" => "Allows deletion of washing machines",

            /**
             * The WASHING MACHINE RESERVATION specific permissions
             */
            "washing.machine.reservation.create" => "Create a new washing machine reservation",
            "washing.machine.reservation.list" => "Shows all washing machine reservations",
            "washing.machine.reservation.show" => "Shows a specific washing machine reservation",
            "washing.machine.reservation.edit" => "Allows editing of washing machine reservations",
            "washing.machine.reservation.delete" => "Allows deletion of washing machine reservations",

            /**
             * The ROLES specific permissions
             */
            "roles.create" => "Create a new role",
            "roles.list" => "Shows all roles",
            "roles.show" => "Shows a specific role",
            "roles.edit" => "Allows editing of roles",
            "roles.delete" => "Allows deletion of roles",

            /**
             * The GUIDE specific permissions
             */
            "guides.create" => "Create a new guide",
            "guides.list" => "Shows all guides",
            "guides.show" => "Shows a specific guide",
            "guides.edit" => "Allows editing of guides",
            "guides.delete" => "Allows deletion of guides",

            /**
             * The LOCATION specific permissions
             */
            "locations.create" => "Create a new location",
            "locations.list" => "Shows all locations",
            "locations.show" => "Shows a specific location",
            "locations.edit" => "Allows editing of locations",
            "locations.delete" => "Allows deletion of locations",

            /**
             * The NEWS specific permissions
             */
            "news.create" => "Create a new location",
            "news.list" => "Shows all locations",
            "news.show" => "Shows a specific location",
            "news.edit" => "Allows editing of locations",
            "news.delete" => "Allows deletion of locations",

            /**
             * The ADMIN PANEL specific permissions
             */
            "admin.panel.show" => "Allows access to administration panel",
        ];

        foreach ($permissions as $key => $value) {

            try {
                if(Permission::findByName($key))
                    continue;
            } catch (Exception $e) {
                $permission = new Permission();

                $permission->name = $key;
                $permission->description = $value;

                $permission->save();
            }
        }
    }
}
