<?php

namespace Database\Seeders;

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

class PermissionSeeder extends Seeder
{
    public function run(): void
    {
        $permissions = [
            // ----- Channels module -----
            ['slug' => 'channels.view',            'name' => 'View Channels',            'module' => 'channels'],
            ['slug' => 'channels.create',          'name' => 'Create Channels',          'module' => 'channels'],
            ['slug' => 'channels.edit',            'name' => 'Edit Channels',            'module' => 'channels'],
            ['slug' => 'channels.delete',          'name' => 'Delete Channels',          'module' => 'channels'],

            // ----- Categories module -----
            ['slug' => 'categories.view',          'name' => 'View Categories',          'module' => 'categories'],
            ['slug' => 'categories.create',        'name' => 'Create Categories',        'module' => 'categories'],
            ['slug' => 'categories.edit',          'name' => 'Edit Categories',          'module' => 'categories'],
            ['slug' => 'categories.delete',        'name' => 'Delete Categories',        'module' => 'categories'],

            // ----- Subcategories module -----
            ['slug' => 'subcategories.view',       'name' => 'View Subcategories',       'module' => 'subcategories'],
            ['slug' => 'subcategories.create',     'name' => 'Create Subcategories',     'module' => 'subcategories'],
            ['slug' => 'subcategories.edit',       'name' => 'Edit Subcategories',       'module' => 'subcategories'],
            ['slug' => 'subcategories.delete',     'name' => 'Delete Subcategories',     'module' => 'subcategories'],

            // ----- Countries of Origin module -----
            ['slug' => 'country-origins.view',     'name' => 'View Countries of Origin', 'module' => 'country-origins'],
            ['slug' => 'country-origins.create',   'name' => 'Create Countries of Origin', 'module' => 'country-origins'],
            ['slug' => 'country-origins.edit',     'name' => 'Edit Countries of Origin', 'module' => 'country-origins'],
            ['slug' => 'country-origins.delete',   'name' => 'Delete Countries of Origin', 'module' => 'country-origins'],

            // ----- Pages module (About Us, Terms & Conditions, ...) -----
            ['slug' => 'pages.view',               'name' => 'View Pages',               'module' => 'pages'],
            ['slug' => 'pages.create',             'name' => 'Create Pages',             'module' => 'pages'],
            ['slug' => 'pages.edit',               'name' => 'Edit Pages',               'module' => 'pages'],
            ['slug' => 'pages.delete',             'name' => 'Delete Pages',             'module' => 'pages'],

            // ----- Products module -----
            ['slug' => 'products.view',            'name' => 'View Products',            'module' => 'products'],
            ['slug' => 'products.create',          'name' => 'Create Products',          'module' => 'products'],
            ['slug' => 'products.edit',            'name' => 'Edit Products',            'module' => 'products'],
            ['slug' => 'products.delete',          'name' => 'Delete Products',          'module' => 'products'],
            ['slug' => 'products.toggle-website',  'name' => 'Toggle Website Visibility','module' => 'products'],

            // ----- Suppliers module -----
            ['slug' => 'suppliers.view',           'name' => 'View Suppliers',           'module' => 'suppliers'],
            ['slug' => 'suppliers.create',         'name' => 'Create Suppliers',         'module' => 'suppliers'],
            ['slug' => 'suppliers.edit',           'name' => 'Edit Suppliers',           'module' => 'suppliers'],
            ['slug' => 'suppliers.delete',         'name' => 'Delete Suppliers',         'module' => 'suppliers'],

            // ----- Racks module -----
            ['slug' => 'racks.view',               'name' => 'View Racks',               'module' => 'racks'],
            ['slug' => 'racks.create',             'name' => 'Create Racks',             'module' => 'racks'],
            ['slug' => 'racks.edit',               'name' => 'Edit Racks',               'module' => 'racks'],
            ['slug' => 'racks.delete',             'name' => 'Delete Racks',             'module' => 'racks'],

            // ----- Locations module (sales venues) -----
            ['slug' => 'locations.view',           'name' => 'View Locations',           'module' => 'locations'],
            ['slug' => 'locations.create',         'name' => 'Create Locations',         'module' => 'locations'],
            ['slug' => 'locations.edit',           'name' => 'Edit Locations',           'module' => 'locations'],
            ['slug' => 'locations.delete',         'name' => 'Delete Locations',         'module' => 'locations'],

            // ----- Purchases module -----
            ['slug' => 'purchases.view',           'name' => 'View Purchases',           'module' => 'purchases'],
            ['slug' => 'purchases.create',         'name' => 'Create Purchases',         'module' => 'purchases'],
            ['slug' => 'purchases.edit',           'name' => 'Edit Purchases',           'module' => 'purchases'],
            ['slug' => 'purchases.delete',         'name' => 'Delete Purchases',         'module' => 'purchases'],
            ['slug' => 'purchases.post',           'name' => 'Post Purchases',           'module' => 'purchases'],

            // ----- Customers module -----
            ['slug' => 'customers.view',           'name' => 'View Customers',           'module' => 'customers'],
            ['slug' => 'customers.create',         'name' => 'Create Customers',         'module' => 'customers'],
            ['slug' => 'customers.edit',           'name' => 'Edit Customers',           'module' => 'customers'],
            ['slug' => 'customers.delete',         'name' => 'Delete Customers',         'module' => 'customers'],

            // ----- Sales module -----
            ['slug' => 'sales.view',               'name' => 'View Sales',               'module' => 'sales'],
            ['slug' => 'sales.create',             'name' => 'Create Sales (Terminal)',  'module' => 'sales'],
            ['slug' => 'sales.edit',               'name' => 'Edit Sales',               'module' => 'sales'],
            ['slug' => 'sales.delete',             'name' => 'Delete Sales',             'module' => 'sales'],
            ['slug' => 'sales.post',               'name' => 'Post / Complete Sales',    'module' => 'sales'],
            ['slug' => 'sales.import',             'name' => 'Import Sales (Bulk Upload)', 'module' => 'sales'],

            // ----- Stock (read-only inventory reports) -----
            ['slug' => 'stock.view',               'name' => 'View Stock Reports',       'module' => 'stock'],
            ['slug' => 'stock.adjust',             'name' => 'Adjust Stock Manually',    'module' => 'stock'],

            // ----- Stock Transfers module -----
            ['slug' => 'stock-transfers.view',     'name' => 'View Stock Transfers',     'module' => 'stock-transfers'],
            ['slug' => 'stock-transfers.create',   'name' => 'Create Stock Transfers',   'module' => 'stock-transfers'],
            ['slug' => 'stock-transfers.edit',     'name' => 'Edit Stock Transfers',     'module' => 'stock-transfers'],
            ['slug' => 'stock-transfers.delete',   'name' => 'Delete Stock Transfers',   'module' => 'stock-transfers'],
            ['slug' => 'stock-transfers.post',     'name' => 'Post / Receive Transfers', 'module' => 'stock-transfers'],

            // ----- Stock Audits module (physical stock-take) -----
            ['slug' => 'stock-audits.view',        'name' => 'View Stock Audits',         'module' => 'stock-audits'],
            ['slug' => 'stock-audits.create',      'name' => 'Start Stock Audits',        'module' => 'stock-audits'],
            ['slug' => 'stock-audits.scan',        'name' => 'Scan Items During Audit',   'module' => 'stock-audits'],
            ['slug' => 'stock-audits.complete',    'name' => 'Complete / Cancel Audits',  'module' => 'stock-audits'],
            ['slug' => 'stock-audits.write-off',   'name' => 'Write Off Missing Stock',   'module' => 'stock-audits'],

            // ----- Banners module -----
            ['slug' => 'banners.view',             'name' => 'View Banners',              'module' => 'banners'],
            ['slug' => 'banners.create',           'name' => 'Create Banners',            'module' => 'banners'],
            ['slug' => 'banners.edit',             'name' => 'Edit Banners',              'module' => 'banners'],
            ['slug' => 'banners.delete',           'name' => 'Delete Banners',            'module' => 'banners'],

            // ----- Blog module -----
            ['slug' => 'blogs.view',               'name' => 'View Blog Posts',           'module' => 'blogs'],
            ['slug' => 'blogs.create',             'name' => 'Create Blog Posts',         'module' => 'blogs'],
            ['slug' => 'blogs.edit',               'name' => 'Edit Blog Posts',           'module' => 'blogs'],
            ['slug' => 'blogs.delete',             'name' => 'Delete Blog Posts',         'module' => 'blogs'],

            // ----- Barcodes -----
            ['slug' => 'barcodes.view',            'name' => 'View Barcodes',            'module' => 'barcodes'],
            ['slug' => 'barcodes.print',           'name' => 'Print Barcode Labels',     'module' => 'barcodes'],

            // ----- User & Role administration -----
            ['slug' => 'users.view',               'name' => 'View Users',               'module' => 'users'],
            ['slug' => 'users.create',             'name' => 'Create Users',             'module' => 'users'],
            ['slug' => 'users.edit',               'name' => 'Edit Users',               'module' => 'users'],
            ['slug' => 'users.delete',             'name' => 'Delete Users',             'module' => 'users'],

            ['slug' => 'roles.view',               'name' => 'View Roles',               'module' => 'roles'],
            ['slug' => 'roles.create',             'name' => 'Create Roles',             'module' => 'roles'],
            ['slug' => 'roles.edit',               'name' => 'Edit Roles',               'module' => 'roles'],
            ['slug' => 'roles.delete',             'name' => 'Delete Roles',             'module' => 'roles'],

            ['slug' => 'permissions.view',         'name' => 'View Permissions',         'module' => 'permissions'],
            ['slug' => 'permissions.create',       'name' => 'Create Permissions',       'module' => 'permissions'],
            ['slug' => 'permissions.edit',         'name' => 'Edit Permissions',         'module' => 'permissions'],
            ['slug' => 'permissions.delete',       'name' => 'Delete Permissions',       'module' => 'permissions'],
        ];

        foreach ($permissions as $row) {
            Permission::updateOrCreate(['slug' => $row['slug']], $row);
        }
    }
}
