import type { DefaultSession } from 'next-auth';
import type { Permission } from '@/lib/auth/permissions';

declare module 'next-auth' {
  interface Session {
    user: DefaultSession['user'] & {
      id: string;
      systemRole: string;
      activeOrganizationId: string | null;
      activeOrganizationName: string | null;
      activeOrganizationPlan: string | null;
      membershipRole: string | null;
      role: string | null;
      employeeCode: string | null;
      employeeId: number | null;
      provider: string | null;
      businessRole: 'IT' | 'HRD' | 'EMPLOYEE' | null;
      permissions: Permission[];
      effectivePermissions: Permission[];
      permissionTemplateIds: number[];
      organizations: Array<{
        id: string;
        name: string;
        slug: string;
        membershipRole: string;
        role: string;
        plan: string;
        imageUrl: string | null;
        permissionTemplateIds: number[];
      }>;
    };
  }

  interface User {
    id: string;
    systemRole?: string;
    activeOrganizationId?: string | null;
    employeeCode?: string | null;
    employeeId?: number | null;
    provider?: string | null;
  }
}

declare module 'next-auth/jwt' {
  interface JWT {
    sub?: string;
  }
}
