import type { TenantSummary } from "../../../lib/adminApi";

export const GLOBAL_PERSONAL_TENANT_ID =
  import.meta.env.VITE_PERSONAL_TENANT_ID ||
  "9607eb7b-04d2-42ab-80fe-780fe21c7e8f";

export const GLOBAL_PERSONAL_TENANT_SLUG =
  import.meta.env.VITE_PERSONAL_TENANT_SLUG || "personal";

export function isPersonalTenant(
  tenant: Pick<TenantSummary, "name" | "slug" | "type">,
) {
  return (
    tenant.slug === GLOBAL_PERSONAL_TENANT_SLUG ||
    (tenant.type === "PERSONAL" && tenant.name.toLowerCase() === "personal")
  );
}

export function resolvePersonalTenant(tenants: TenantSummary[]): TenantSummary {
  const tenant = tenants.find(isPersonalTenant);
  if (tenant) return tenant;

  return {
    id: GLOBAL_PERSONAL_TENANT_ID,
    slug: GLOBAL_PERSONAL_TENANT_SLUG,
    name: "Personal",
    type: "PERSONAL",
    description: "개인 사용자 기본 루트 테넌트",
    status: "active",
    memberCount: 0,
    createdAt: "2026-05-04T06:52:59.187802Z",
    updatedAt: "2026-05-04T06:52:59.191145Z",
  };
}
