import { jsxs as s, jsx as e } from "react/jsx-runtime";
import { useTranslation as n } from "react-i18next";
import { Link as a } from "react-router-dom";
import { Link2 as m, AlertTriangle as p, XCircle as u, CheckCircle2 as c, Code2 as l, Zap as h, ArrowRight as i } from "lucide-react";
function t({ code: r, language: d = "csharp", title: o }) {
  return /* @__PURE__ */ s("div", { className: "rounded-lg overflow-hidden", children: [
    o && /* @__PURE__ */ e("div", { className: "bg-[var(--bg-tertiary)] px-4 py-2 border-b border-[var(--border-color)]", children: /* @__PURE__ */ e("span", { className: "text-sm font-medium", children: o }) }),
    /* @__PURE__ */ e("pre", { className: "bg-[var(--bg-tertiary)] p-4 overflow-x-auto", children: /* @__PURE__ */ e("code", { className: `language-${d} text-sm`, children: r }) })
  ] });
}
function y() {
  const { t: r } = n("docs");
  return /* @__PURE__ */ s("div", { className: "space-y-8", children: [
    /* @__PURE__ */ s("div", { className: "flex items-center gap-2 text-sm text-[var(--text-secondary)]", children: [
      /* @__PURE__ */ e(a, { to: "/system/docs", className: "hover:text-[var(--color-primary-600)]", children: r("developer.crossSchemaFk.breadcrumb.documentation") }),
      /* @__PURE__ */ e("span", { children: "/" }),
      /* @__PURE__ */ e(a, { to: "/system/docs/developer", className: "hover:text-[var(--color-primary-600)]", children: r("developer.crossSchemaFk.breadcrumb.developer") }),
      /* @__PURE__ */ e("span", { children: "/" }),
      /* @__PURE__ */ e("span", { children: r("developer.crossSchemaFk.breadcrumb.fkCrossSchema") })
    ] }),
    /* @__PURE__ */ s("div", { children: [
      /* @__PURE__ */ s("h1", { className: "text-3xl font-bold mb-4 flex items-center gap-3", children: [
        /* @__PURE__ */ e(m, { className: "w-8 h-8 text-[var(--color-primary-600)]" }),
        r("developer.crossSchemaFk.header.title")
      ] }),
      /* @__PURE__ */ e("p", { className: "text-lg text-[var(--text-secondary)]", children: r("developer.crossSchemaFk.header.subtitle") })
    ] }),
    /* @__PURE__ */ s("section", { className: "card p-6", children: [
      /* @__PURE__ */ s("h2", { className: "text-xl font-bold mb-4 flex items-center gap-2", children: [
        /* @__PURE__ */ e(p, { className: "w-5 h-5 text-[var(--warning-text)]" }),
        r("developer.crossSchemaFk.problem.title")
      ] }),
      /* @__PURE__ */ s("div", { className: "space-y-4 text-[var(--text-secondary)]", children: [
        /* @__PURE__ */ s("p", { children: [
          r("developer.crossSchemaFk.problem.intro"),
          " ",
          /* @__PURE__ */ e("code", { className: "px-1 bg-[var(--bg-secondary)] rounded", children: "ExtensionsDbContext" }),
          " ",
          r("developer.crossSchemaFk.problem.intro"),
          " ",
          /* @__PURE__ */ e("code", { className: "px-1 bg-[var(--bg-secondary)] rounded", children: "CoreDbContext" }),
          "."
        ] }),
        /* @__PURE__ */ e("p", { children: r("developer.crossSchemaFk.problem.intro2") }),
        /* @__PURE__ */ s("ul", { className: "list-disc list-inside space-y-2 ml-4", children: [
          /* @__PURE__ */ e("li", { children: r("developer.crossSchemaFk.problem.limitations.item1") }),
          /* @__PURE__ */ s("li", { children: [
            r("developer.crossSchemaFk.problem.limitations.item2"),
            " ",
            /* @__PURE__ */ e("code", { className: "px-1 bg-[var(--bg-secondary)] rounded", children: ".Include()" })
          ] }),
          /* @__PURE__ */ e("li", { children: r("developer.crossSchemaFk.problem.limitations.item3") })
        ] })
      ] }),
      /* @__PURE__ */ s("div", { className: "mt-6", children: [
        /* @__PURE__ */ s("h3", { className: "font-semibold mb-2 flex items-center gap-2", children: [
          /* @__PURE__ */ e(u, { className: "w-4 h-4 text-[var(--error-text)]" }),
          r("developer.crossSchemaFk.problem.badExample.title")
        ] }),
        /* @__PURE__ */ e(t, { title: r("developer.crossSchemaFk.problem.badExample.codeTitle"), code: `// NE FAITES PAS CELA
public class Order : BaseAuditableEntity
{
    public string OrderNumber { get; private set; }
    public Guid CustomerId { get; private set; }

    // ERREUR: ExtensionsDbContext ne connait pas User
    public User Customer { get; private set; }  // <-- NE FONCTIONNE PAS
}

// ERREUR: Include impossible
var order = await _context.Orders
    .Include(o => o.Customer)  // <-- ERREUR DE COMPILATION
    .FirstOrDefaultAsync(o => o.Id == id);` })
      ] })
    ] }),
    /* @__PURE__ */ s("section", { className: "card p-6", children: [
      /* @__PURE__ */ s("h2", { className: "text-xl font-bold mb-4 flex items-center gap-2", children: [
        /* @__PURE__ */ e(c, { className: "w-5 h-5 text-[var(--success-text)]" }),
        r("developer.crossSchemaFk.solution.title")
      ] }),
      /* @__PURE__ */ e("div", { className: "space-y-4 text-[var(--text-secondary)]", children: /* @__PURE__ */ s("p", { children: [
        r("developer.crossSchemaFk.solution.intro"),
        " ",
        /* @__PURE__ */ e("code", { className: "px-1 bg-[var(--bg-secondary)] rounded", children: "ICoreDataService" })
      ] }) }),
      /* @__PURE__ */ s("div", { className: "grid md:grid-cols-2 gap-6 mt-6", children: [
        /* @__PURE__ */ s("div", { children: [
          /* @__PURE__ */ s("h3", { className: "font-semibold mb-2 flex items-center gap-2", children: [
            /* @__PURE__ */ e(c, { className: "w-4 h-4 text-[var(--success-text)]" }),
            r("developer.crossSchemaFk.solution.entity.title")
          ] }),
          /* @__PURE__ */ e(t, { title: r("developer.crossSchemaFk.solution.entity.codeTitle"), code: `public class Order : BaseAuditableEntity
{
    public string OrderNumber { get; private set; }

    // Stocker seulement le GUID
    public Guid CustomerId { get; private set; }

    // PAS de navigation property vers User
    // private User Customer; // NON!

    // Factory method
    public static Order Create(
        string orderNumber,
        Guid customerId,  // <-- GUID seulement
        decimal totalAmount)
    {
        return new Order
        {
            OrderNumber = orderNumber,
            CustomerId = customerId,
            // ...
        };
    }
}` })
        ] }),
        /* @__PURE__ */ s("div", { children: [
          /* @__PURE__ */ s("h3", { className: "font-semibold mb-2 flex items-center gap-2", children: [
            /* @__PURE__ */ e(c, { className: "w-4 h-4 text-[var(--success-text)]" }),
            r("developer.crossSchemaFk.solution.service.title")
          ] }),
          /* @__PURE__ */ e(t, { title: r("developer.crossSchemaFk.solution.service.codeTitle"), code: `public class OrderService : IOrderService
{
    private readonly IExtensionsDbContext _context;
    private readonly ICoreDataService _coreData;

    public OrderService(
        IExtensionsDbContext context,
        ICoreDataService coreData)
    {
        _context = context;
        _coreData = coreData;
    }

    public async Task<OrderDto> GetOrderAsync(Guid id)
    {
        // 1. Recuperer l'order
        var order = await _context.Orders
            .FirstOrDefaultAsync(o => o.Id == id);

        // 2. Recuperer le user via ICoreDataService
        var customer = await _coreData
            .GetUserBasicInfoAsync(order.CustomerId);

        // 3. Combiner les donnees
        return new OrderDto
        {
            Id = order.Id,
            OrderNumber = order.OrderNumber,
            CustomerName = customer?.DisplayName
        };
    }
}` })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ s("section", { className: "card p-6", children: [
      /* @__PURE__ */ s("h2", { className: "text-xl font-bold mb-4 flex items-center gap-2", children: [
        /* @__PURE__ */ e(l, { className: "w-5 h-5" }),
        r("developer.crossSchemaFk.coreDataService.title")
      ] }),
      /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)] mb-4", children: r("developer.crossSchemaFk.coreDataService.intro") }),
      /* @__PURE__ */ e(t, { title: r("developer.crossSchemaFk.coreDataService.codeTitle"), code: `public interface ICoreDataService
{
    // === USERS ===
    Task<User?> GetUserByIdAsync(Guid userId, CancellationToken ct = default);
    Task<IReadOnlyList<User>> GetUsersByIdsAsync(IEnumerable<Guid> userIds, CancellationToken ct = default);
    Task<User?> GetUserByEmailAsync(string email, CancellationToken ct = default);
    Task<UserBasicInfo?> GetUserBasicInfoAsync(Guid userId, CancellationToken ct = default);

    // === ROLES ===
    Task<Role?> GetRoleByIdAsync(Guid roleId, CancellationToken ct = default);
    Task<IReadOnlyList<Role>> GetRolesByIdsAsync(IEnumerable<Guid> roleIds, CancellationToken ct = default);
    Task<IReadOnlyList<Role>> GetUserRolesAsync(Guid userId, CancellationToken ct = default);

    // === NAVIGATION ===
    Task<NavigationApplication?> GetNavigationApplicationByIdAsync(Guid appId, CancellationToken ct = default);
    Task<NavigationModule?> GetNavigationModuleByIdAsync(Guid moduleId, CancellationToken ct = default);

    // === TENANT ===
    Task<Organisation?> GetTenantByIdAsync(Guid tenantId, CancellationToken ct = default);
    Task<bool> TenantExistsAsync(Guid tenantId, CancellationToken ct = default);
}` })
    ] }),
    /* @__PURE__ */ s("section", { className: "card p-6", children: [
      /* @__PURE__ */ s("h2", { className: "text-xl font-bold mb-4 flex items-center gap-2", children: [
        /* @__PURE__ */ e(h, { className: "w-5 h-5 text-[var(--warning-text)]" }),
        r("developer.crossSchemaFk.performance.title")
      ] }),
      /* @__PURE__ */ e("div", { className: "space-y-4 text-[var(--text-secondary)]", children: /* @__PURE__ */ e("p", { children: r("developer.crossSchemaFk.performance.intro") }) }),
      /* @__PURE__ */ e("div", { className: "mt-4", children: /* @__PURE__ */ e(t, { title: r("developer.crossSchemaFk.performance.codeTitle"), code: `public async Task<IReadOnlyList<OrderDto>> GetOrdersAsync()
{
    // 1. Charger tous les orders
    var orders = await _context.Orders
        .AsNoTracking()
        .ToListAsync();

    // 2. Extraire les IDs uniques
    var customerIds = orders
        .Select(o => o.CustomerId)
        .Distinct()
        .ToList();

    // 3. Charger tous les users en UNE requete
    var customers = await _coreData
        .GetUsersBasicInfoAsync(customerIds);

    // 4. Creer un dictionnaire pour lookup rapide
    var customerDict = customers.ToDictionary(c => c.Id);

    // 5. Mapper les resultats
    return orders.Select(o => new OrderDto
    {
        Id = o.Id,
        OrderNumber = o.OrderNumber,
        CustomerName = customerDict.TryGetValue(o.CustomerId, out var c)
            ? c.DisplayName
            : "Unknown"
    }).ToList();
}` }) })
    ] }),
    /* @__PURE__ */ s("section", { className: "card p-6", children: [
      /* @__PURE__ */ s("h2", { className: "text-xl font-bold mb-4 flex items-center gap-2", children: [
        /* @__PURE__ */ e(l, { className: "w-5 h-5" }),
        r("developer.crossSchemaFk.configuration.title")
      ] }),
      /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)] mb-4", children: r("developer.crossSchemaFk.configuration.intro") }),
      /* @__PURE__ */ e(t, { title: r("developer.crossSchemaFk.configuration.codeTitle"), code: `public class OrderConfiguration : IEntityTypeConfiguration<Order>
{
    public void Configure(EntityTypeBuilder<Order> builder)
    {
        builder.ToTable("biz_Orders", SchemaConstants.Extensions);

        builder.HasKey(e => e.Id);

        // CustomerId est un GUID simple, pas une FK EF Core
        builder.Property(e => e.CustomerId)
            .IsRequired();

        // Index pour les recherches par customer
        builder.HasIndex(e => e.CustomerId);

        // PAS DE .HasOne() ou .HasForeignKey() vers User!
        // builder.HasOne<User>()... // NON!
    }
}` })
    ] }),
    /* @__PURE__ */ s("section", { className: "card p-6", children: [
      /* @__PURE__ */ e("h2", { className: "text-xl font-bold mb-4", children: r("developer.crossSchemaFk.faq.title") }),
      /* @__PURE__ */ s("div", { className: "space-y-4", children: [
        /* @__PURE__ */ s("div", { className: "p-4 bg-[var(--bg-secondary)] rounded-lg", children: [
          /* @__PURE__ */ e("h3", { className: "font-semibold mb-2", children: r("developer.crossSchemaFk.faq.question1") }),
          /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)]", children: r("developer.crossSchemaFk.faq.answer1") })
        ] }),
        /* @__PURE__ */ s("div", { className: "p-4 bg-[var(--bg-secondary)] rounded-lg", children: [
          /* @__PURE__ */ e("h3", { className: "font-semibold mb-2", children: r("developer.crossSchemaFk.faq.question2") }),
          /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)]", children: r("developer.crossSchemaFk.faq.answer2") })
        ] }),
        /* @__PURE__ */ s("div", { className: "p-4 bg-[var(--bg-secondary)] rounded-lg", children: [
          /* @__PURE__ */ e("h3", { className: "font-semibold mb-2", children: r("developer.crossSchemaFk.faq.question3") }),
          /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)]", children: r("developer.crossSchemaFk.faq.answer3") })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ s("div", { className: "flex justify-between pt-4 border-t border-[var(--border-color)]", children: [
      /* @__PURE__ */ s(
        a,
        {
          to: "/system/docs/developer/dual-dbcontext",
          className: "flex items-center gap-2 text-[var(--color-primary-600)] hover:underline",
          children: [
            /* @__PURE__ */ e(i, { className: "w-4 h-4 rotate-180" }),
            r("developer.crossSchemaFk.navigation.prevPage")
          ]
        }
      ),
      /* @__PURE__ */ s(
        a,
        {
          to: "/system/docs/developer/infrastructure",
          className: "flex items-center gap-2 text-[var(--color-primary-600)] hover:underline",
          children: [
            r("developer.crossSchemaFk.navigation.nextPage"),
            /* @__PURE__ */ e(i, { className: "w-4 h-4" })
          ]
        }
      )
    ] })
  ] });
}
export {
  y as CrossSchemaFkPage
};
//# sourceMappingURL=CrossSchemaFkPage-BchJFOmH.js.map
