/*
|--------------------------------------------------------------------------
| Agência PSI
|--------------------------------------------------------------------------
| Criado e desenvolvido por Leonardo Nohama
|
| Tecnologia aplicada à escuta.
| Estrutura para o cuidado.
|
| Arquivo: src/router/routes.clinic.js
| Data: 2026
| Local: São Carlos/SP — Brasil
|--------------------------------------------------------------------------
| © 2026 — Todos os direitos reservados
|--------------------------------------------------------------------------
*/
import RouterPassthrough from '@/layout/RouterPassthrough.vue';

// ── Rotas fullscreen — ficam fora do AppLayout compartilhado ──────────────
export const clinicStandalone = [
    {
        path: '/admin/setup',
        name: 'admin.setup',
        component: () => import('@/features/setup/SetupWizardPage.vue'),
        meta: { area: 'admin', requiresAuth: true, roles: ['clinic_admin'], fullscreen: true }
    }
];

// ── Rotas de app — serão filhas do AppLayout compartilhado no index.js ────
export default {
    path: 'admin',
    component: RouterPassthrough,
    meta: {
        area: 'admin',
        requiresAuth: true,
        roles: ['clinic_admin']
    },
    children: [
        // ======================================================
        // 📊 DASHBOARD
        // ======================================================
        { path: '', name: 'admin.dashboard', component: () => import('@/views/pages/clinic/ClinicDashboard.vue') },

        // ======================================================
        // 💬 CONVERSAS (CRM de WhatsApp)
        // ======================================================
        // Redirect pro layout Melissa (versão oficial). RLS do Postgres
        // garante que o admin vê dados da clínica e o terapeuta vê só os
        // dele — independente da rota de entrada. A `CRMConversasPage`
        // antiga continua no repo (sem rota apontando) até validarmos.
        {
            path: 'conversas',
            name: 'admin-conversas',
            redirect: { name: 'Melissa', params: { secao: 'conversas' } }
        },

        // ======================================================
        // 🧩 CLÍNICA — MÓDULOS (tenant_features)
        // ======================================================
        {
            path: 'clinic/features',
            name: 'admin-clinic-features',
            component: () => import('@/views/pages/clinic/clinic/ClinicFeaturesPage.vue'),
            meta: { roles: ['clinic_admin', 'tenant_admin'] }
        },
        {
            path: 'clinic/professionals',
            name: 'admin-clinic-professionals',
            component: () => import('@/views/pages/clinic/clinic/ClinicProfessionalsPage.vue'),
            meta: { requiresAuth: true, roles: ['clinic_admin', 'tenant_admin'] }
        },

        // ======================================================
        // 💳 MEU PLANO
        // ======================================================
        {
            path: 'meu-plano',
            name: 'admin-meu-plano',
            component: () => import('@/views/pages/billing/ClinicMeuPlanoPage.vue')
        },

        // ======================================================
        // 📅 AGENDA DA CLÍNICA
        // ======================================================
        {
            path: 'agenda/clinica',
            name: 'admin-agenda-clinica',
            component: () => import('@/features/agenda/pages/AgendaClinicaPage.vue'),
            meta: { feature: 'agenda.view', roles: ['clinic_admin', 'tenant_admin'] }
        },

        // Recorrências
        {
            path: 'agenda/recorrencias',
            name: 'admin-agenda-recorrencias',
            component: () => import('@/features/agenda/pages/AgendaRecorrenciasPage.vue'),
            meta: { feature: 'agenda.view', roles: ['clinic_admin', 'tenant_admin'], mode: 'clinic' }
        },

        // ✅ Compromissos determinísticos
        {
            path: 'agenda/compromissos',
            name: 'admin-agenda-compromissos',
            component: () => import('@/features/agenda/pages/CompromissosDeterminados.vue'),
            meta: { feature: 'agenda.view', roles: ['clinic_admin', 'tenant_admin'] }
        },

        // ======================================================
        // 👥 PACIENTES
        // ======================================================
        {
            path: 'pacientes',
            name: 'admin-pacientes',
            component: () => import('@/features/patients/PatientsListPage.vue'),
            meta: { tenantFeature: 'patients' }
        },
        {
            path: 'pacientes/cadastro',
            name: 'admin-pacientes-cadastro',
            component: () => import('@/features/patients/cadastro/PatientsCadastroPage.vue'),
            meta: { tenantFeature: 'patients' }
        },
        {
            path: 'pacientes/cadastro/:id',
            name: 'admin-pacientes-cadastro-edit',
            component: () => import('@/features/patients/cadastro/PatientsCadastroPage.vue'),
            props: true,
            meta: { tenantFeature: 'patients' }
        },
        {
            path: 'pacientes/grupos',
            name: 'admin-pacientes-grupos',
            component: () => import('@/features/patients/grupos/GruposPacientesPage.vue'),
            meta: { tenantFeature: 'patients' }
        },
        {
            path: 'pacientes/tags',
            name: 'admin-pacientes-tags',
            component: () => import('@/features/patients/tags/TagsPage.vue'),
            meta: { tenantFeature: 'patients' }
        },
        {
            path: 'pacientes/medicos',
            name: 'admin-pacientes-medicos',
            component: () => import('@/features/patients/medicos/MedicosPage.vue'),
            meta: { tenantFeature: 'patients' }
        },
        {
            path: 'pacientes/link-externo',
            name: 'admin-pacientes-link-externo',
            component: () => import('@/features/patients/cadastro/PatientsExternalLinkPage.vue'),
            meta: { tenantFeature: 'patients' }
        },
        {
            path: 'pacientes/cadastro/recebidos',
            name: 'admin-pacientes-recebidos',
            component: () => import('@/features/patients/cadastro/recebidos/CadastrosRecebidosPage.vue'),
            meta: { tenantFeature: 'patients' }
        },

        // ======================================================
        // 📄 DOCUMENTOS
        // ======================================================
        // /documents/templates removido — mudou pra /configuracoes/documentos/templates
        // (setup/config, não operação clínica).

        // ======================================================
        // 🔐 SEGURANÇA
        // ======================================================
        {
            path: 'settings/security',
            name: 'admin-settings-security',
            component: () => import('@/views/pages/auth/SecurityPage.vue')
        },

        // ======================================================
        // 👥 MEMBROS & CONVITES
        // ======================================================
        {
            path: 'members',
            name: 'admin-members',
            component: () => import('@/views/pages/admin/MembersPage.vue'),
            meta: { roles: ['tenant_admin', 'clinic_admin'] }
        },

        // ======================================================
        // 🔒 MÓDULO PRO — Online Scheduling
        // ======================================================
        {
            path: 'online-scheduling',
            name: 'admin-online-scheduling',
            component: () => import('@/views/pages/clinic/OnlineSchedulingAdminPage.vue'),
            meta: { feature: 'online_scheduling.manage' }
        },

        // ======================================================
        // 🔒 PRO — Agendamentos Recebidos
        // ======================================================
        {
            path: 'agendamentos-recebidos',
            name: 'admin-agendamentos-recebidos',
            component: () => import('@/features/agenda/pages/AgendamentosRecebidosPage.vue'),
            meta: { feature: 'online_scheduling.manage' }
        },

        // ======================================================
        // 💰 FINANCEIRO
        // ======================================================
        {
            path: 'financeiro',
            name: 'admin-financeiro',
            component: () => import('@/features/financeiro/pages/FinanceiroDashboardPage.vue')
        },
        {
            path: 'financeiro/lancamentos',
            name: 'admin-financeiro-lancamentos',
            component: () => import('@/features/financeiro/pages/FinanceiroPage.vue')
        }
    ]
};
