<?php

namespace App\Enums;

class ClientPermission
{
    // Ürün İzinleri
    const VIEW_SERVICES = 'view_services';

    const MANAGE_SERVICES = 'manage_services';

    // Domain İzinleri
    const VIEW_DOMAINS = 'view_domains';

    const MANAGE_DOMAINS = 'manage_domains';

    // Fatura İzinleri
    const VIEW_INVOICES = 'view_invoices';

    // PRC-404 / E-002 — Previously hidden from getPermissionGroups() so
    // it couldn't be granted via the invite UI; the middleware mapping
    // for snapshot edit + mass payment then always rejected switched
    // users. Now exposed: account owners can delegate the permission.
    const MANAGE_INVOICES = 'manage_invoices';

    // Destek İzinleri
    const VIEW_TICKETS = 'view_tickets';

    const REPLY_TICKETS = 'reply_tickets';

    const CREATE_TICKETS = 'create_tickets';

    // Sistem İzinleri
    const VIEW_DASHBOARD = 'view_dashboard';

    public static function all(): array
    {
        return [
            self::VIEW_SERVICES,
            self::MANAGE_SERVICES,
            self::VIEW_DOMAINS,
            self::MANAGE_DOMAINS,
            self::VIEW_INVOICES,
            self::MANAGE_INVOICES,
            self::VIEW_TICKETS,
            self::REPLY_TICKETS,
            self::CREATE_TICKETS,
            self::VIEW_DASHBOARD,
        ];
    }

    public static function getPermissionGroups(): array
    {
        return [
            'services' => [
                'label' => __('enums.client_permission_groups_services'),
                'permissions' => [
                    self::VIEW_SERVICES => __('enums.client_permission_view_services'),
                    self::MANAGE_SERVICES => __('enums.client_permission_manage_services'),
                ],
            ],
            'domains' => [
                'label' => __('enums.client_permission_groups_domains'),
                'permissions' => [
                    self::VIEW_DOMAINS => __('enums.client_permission_view_domains'),
                    self::MANAGE_DOMAINS => __('enums.client_permission_manage_domains'),
                ],
            ],
            'invoices' => [
                'label' => __('enums.client_permission_groups_invoices'),
                'permissions' => [
                    self::VIEW_INVOICES => __('enums.client_permission_view_invoices'),
                    self::MANAGE_INVOICES => __('enums.client_permission_manage_invoices'),
                ],
            ],
            'tickets' => [
                'label' => __('enums.client_permission_groups_tickets'),
                'permissions' => [
                    self::VIEW_TICKETS => __('enums.client_permission_view_tickets'),
                    self::REPLY_TICKETS => __('enums.client_permission_reply_tickets'),
                    self::CREATE_TICKETS => __('enums.client_permission_create_tickets'),
                ],
            ],
            'system' => [
                'label' => __('enums.client_permission_groups_system'),
                'permissions' => [
                    self::VIEW_DASHBOARD => __('enums.client_permission_view_dashboard'),
                ],
            ],
        ];
    }

    public static function getLabels(): array
    {
        $labels = [];
        foreach (self::getPermissionGroups() as $group) {
            $labels = array_merge($labels, $group['permissions']);
        }

        return $labels;
    }
}
