<?php

namespace Database\Seeders;

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

class RolePermissionSeeder extends Seeder
{
    public function run(): void
    {
        $developer = Role::firstOrCreate(['name' => 'Developer']);
        $owner = Role::firstOrCreate(['name' => 'Owner']);
        $leader = Role::firstOrCreate(['name' => 'Leader']);
        $admin = Role::firstOrCreate(['name' => 'Admin']);
        $partner = Role::firstOrCreate(['name' => 'Partner']);
        $customer = Role::firstOrCreate(['name' => 'Customer']);

        $permissions = [
            'view account',
            'update account',

            'view profile',
            'update profile',

            'view password',
            'update password',

            'view overview',

            'view outlet',
            'create outlet',
            'update outlet',
            'delete outlet',

            'view user',
            'create user',
            'update user',
            'delete user',

            'view formula',
            'create formula',
            'update formula',
            'delete formula',

            'view tier',
            'create tier',
            'update tier',
            'delete tier',

            'view tier reward',
            'create tier reward',
            'update tier reward',
            'delete tier reward',

            'view voucher',
            'create voucher',
            'update voucher',
            'delete voucher',

            'view customer',
            'create customer',
            'update customer',
            'delete customer',

            'view category',
            'create category',
            'update category',
            'delete category',

            'view brand',
            'create brand',
            'update brand',
            'delete brand',

            'view perfume',
            'create perfume',
            'update perfume',
            'delete perfume',
            'audit perfume',

            'view product',
            'create product',
            'update product',
            'delete product',
            'audit product',

            'view bottle',
            'create bottle',
            'update bottle',
            'delete bottle',
            'audit bottle',

            'view expense',
            'create expense',
            'update expense',
            'delete expense',

            'view payroll',
            'manage adjustment',

            'view order',
            'create order',
            'update order',
            'delete order',
            'show order',

            'view purchase',
            'create purchase',
            'delete purchase',

            'view article',
            'create article',
            'update article',
            'delete article',

            'view faq',
            'create faq',
            'update faq',
            'delete faq',

            'view perfume feature',
            'create perfume feature',
            'update perfume feature',
            'delete perfume feature',

            'view choose us',
            'create choose us',
            'update choose us',
            'delete choose us',

            'view application settings',

            'view whatsapp settings',

            'view general settings',
            'update general settings',

            'view contact settings',
            'update contact settings',

            'view seo settings',
            'update seo settings',

            'view social settings',
            'update social settings',
        ];

        foreach ($permissions as $permission) {
            Permission::firstOrCreate(['name' => $permission]);
        }

        $developer->syncPermissions($permissions);

        $owner->syncPermissions($permissions);

        $leader->syncPermissions(array_diff($permissions, [
            'view outlet',
            'create outlet',
            'update outlet',
            'delete outlet',

            'view user',
            'create user',
            'update user',
            'delete user',

            'create tier',
            'update tier',
            'delete tier',

            'create voucher',
            'update voucher',
            'delete voucher',

            'create perfume',
            'update perfume',
            'delete perfume',
            'audit perfume',

            'create product',
            'update product',
            'delete product',
            'audit product',

            'create bottle',
            'update bottle',
            'delete bottle',
            'audit bottle',
        ]));

        $admin->syncPermissions(array_diff($permissions, [
            'view outlet',
            'create outlet',
            'update outlet',
            'delete outlet',

            'view user',
            'create user',
            'update user',
            'delete user',

            'create tier',
            'update tier',
            'delete tier',

            'create voucher',
            'update voucher',
            'delete voucher',

            'create category',
            'update category',
            'delete category',

            'create brand',
            'update brand',
            'delete brand',

            'create perfume',
            'update perfume',
            'delete perfume',
            'audit perfume',

            'create product',
            'update product',
            'delete product',
            'audit product',

            'create bottle',
            'update bottle',
            'delete bottle',
            'audit bottle',

            'view article',
            'create article',
            'update article',
            'delete article',
        ]));

        $partner->syncPermissions([
            'view overview',

            'view account',
            'update account',

            'view profile',
            'update profile',

            'view password',
            'update password',
        ]);

        $customer->syncPermissions([
            'view overview',

            'view account',
            'update account',

            'view profile',
            'update profile',

            'view password',
            'update password',
        ]);
    }
}
