<?php

namespace App\Support;

use App\Models\AdminRole;

/** 平台「站点客服」内置角色：单玩家查询，不含全局经营报表与代理管理。 */
final class SiteCsDefaultRolePermissions
{
    /** @var list<string> */
    private const TEMPLATE_SLUGS = [
        'prd.dashboard.view',
        'prd.users.view_cs',
        'prd.tickets.view',
        'prd.wallet_reconcile.view_cs',
    ];

    /** @return list<string> */
    public static function templateSlugs(): array
    {
        return self::TEMPLATE_SLUGS;
    }

    public static function ensurePlatformSiteCsRole(): AdminRole
    {
        $role = AdminRole::query()->updateOrCreate(
            [
                'slug' => SiteOperatorRoles::SLUG_SITE_CS,
                'scope_type' => AdminRole::SCOPE_SYSTEM,
            ],
            [
                'code' => SiteOperatorRoles::SLUG_SITE_CS,
                'name' => '站点客服',
                'description' => '单站客服：玩家/注单/单用户钱包查询工作台，不含全局报表与代理经营',
                'status' => 1,
                'is_system' => true,
                'sort_order' => 42,
                'owner_agent_id' => null,
                'delegated_from_role_id' => null,
            ],
        );

        $role->syncLegacyPermissionSlugs(
            AdminPermissionInheritance::expand(self::TEMPLATE_SLUGS),
        );

        return $role->fresh() ?? $role;
    }
}
