"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react-i18next"),a=require("react-router-dom"),r=require("lucide-react");function t({code:s,language:o="csharp",title:c}){return e.jsxs("div",{className:"rounded-lg overflow-hidden",children:[c&&e.jsx("div",{className:"bg-[var(--bg-tertiary)] px-4 py-2 border-b border-[var(--border-color)]",children:e.jsx("span",{className:"text-sm font-medium",children:c})}),e.jsx("pre",{className:"bg-[var(--bg-tertiary)] p-4 overflow-x-auto",children:e.jsx("code",{className:`language-${o} text-sm`,children:s})})]})}function i(){const{t:s}=l.useTranslation("docs");return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--text-secondary)]",children:[e.jsx(a.Link,{to:"/system/docs",className:"hover:text-[var(--color-primary-600)]",children:s("developer.crossSchemaFk.breadcrumb.documentation")}),e.jsx("span",{children:"/"}),e.jsx(a.Link,{to:"/system/docs/developer",className:"hover:text-[var(--color-primary-600)]",children:s("developer.crossSchemaFk.breadcrumb.developer")}),e.jsx("span",{children:"/"}),e.jsx("span",{children:s("developer.crossSchemaFk.breadcrumb.fkCrossSchema")})]}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold mb-4 flex items-center gap-3",children:[e.jsx(r.Link2,{className:"w-8 h-8 text-[var(--color-primary-600)]"}),s("developer.crossSchemaFk.header.title")]}),e.jsx("p",{className:"text-lg text-[var(--text-secondary)]",children:s("developer.crossSchemaFk.header.subtitle")})]}),e.jsxs("section",{className:"card p-6",children:[e.jsxs("h2",{className:"text-xl font-bold mb-4 flex items-center gap-2",children:[e.jsx(r.AlertTriangle,{className:"w-5 h-5 text-[var(--warning-text)]"}),s("developer.crossSchemaFk.problem.title")]}),e.jsxs("div",{className:"space-y-4 text-[var(--text-secondary)]",children:[e.jsxs("p",{children:[s("developer.crossSchemaFk.problem.intro")," ",e.jsx("code",{className:"px-1 bg-[var(--bg-secondary)] rounded",children:"ExtensionsDbContext"})," ",s("developer.crossSchemaFk.problem.intro")," ",e.jsx("code",{className:"px-1 bg-[var(--bg-secondary)] rounded",children:"CoreDbContext"}),"."]}),e.jsx("p",{children:s("developer.crossSchemaFk.problem.intro2")}),e.jsxs("ul",{className:"list-disc list-inside space-y-2 ml-4",children:[e.jsx("li",{children:s("developer.crossSchemaFk.problem.limitations.item1")}),e.jsxs("li",{children:[s("developer.crossSchemaFk.problem.limitations.item2")," ",e.jsx("code",{className:"px-1 bg-[var(--bg-secondary)] rounded",children:".Include()"})]}),e.jsx("li",{children:s("developer.crossSchemaFk.problem.limitations.item3")})]})]}),e.jsxs("div",{className:"mt-6",children:[e.jsxs("h3",{className:"font-semibold mb-2 flex items-center gap-2",children:[e.jsx(r.XCircle,{className:"w-4 h-4 text-[var(--error-text)]"}),s("developer.crossSchemaFk.problem.badExample.title")]}),e.jsx(t,{title:s("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);`})]})]}),e.jsxs("section",{className:"card p-6",children:[e.jsxs("h2",{className:"text-xl font-bold mb-4 flex items-center gap-2",children:[e.jsx(r.CheckCircle2,{className:"w-5 h-5 text-[var(--success-text)]"}),s("developer.crossSchemaFk.solution.title")]}),e.jsx("div",{className:"space-y-4 text-[var(--text-secondary)]",children:e.jsxs("p",{children:[s("developer.crossSchemaFk.solution.intro")," ",e.jsx("code",{className:"px-1 bg-[var(--bg-secondary)] rounded",children:"ICoreDataService"})]})}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-6 mt-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-semibold mb-2 flex items-center gap-2",children:[e.jsx(r.CheckCircle2,{className:"w-4 h-4 text-[var(--success-text)]"}),s("developer.crossSchemaFk.solution.entity.title")]}),e.jsx(t,{title:s("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,
            // ...
        };
    }
}`})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-semibold mb-2 flex items-center gap-2",children:[e.jsx(r.CheckCircle2,{className:"w-4 h-4 text-[var(--success-text)]"}),s("developer.crossSchemaFk.solution.service.title")]}),e.jsx(t,{title:s("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
        };
    }
}`})]})]})]}),e.jsxs("section",{className:"card p-6",children:[e.jsxs("h2",{className:"text-xl font-bold mb-4 flex items-center gap-2",children:[e.jsx(r.Code2,{className:"w-5 h-5"}),s("developer.crossSchemaFk.coreDataService.title")]}),e.jsx("p",{className:"text-[var(--text-secondary)] mb-4",children:s("developer.crossSchemaFk.coreDataService.intro")}),e.jsx(t,{title:s("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);
}`})]}),e.jsxs("section",{className:"card p-6",children:[e.jsxs("h2",{className:"text-xl font-bold mb-4 flex items-center gap-2",children:[e.jsx(r.Zap,{className:"w-5 h-5 text-[var(--warning-text)]"}),s("developer.crossSchemaFk.performance.title")]}),e.jsx("div",{className:"space-y-4 text-[var(--text-secondary)]",children:e.jsx("p",{children:s("developer.crossSchemaFk.performance.intro")})}),e.jsx("div",{className:"mt-4",children:e.jsx(t,{title:s("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();
}`})})]}),e.jsxs("section",{className:"card p-6",children:[e.jsxs("h2",{className:"text-xl font-bold mb-4 flex items-center gap-2",children:[e.jsx(r.Code2,{className:"w-5 h-5"}),s("developer.crossSchemaFk.configuration.title")]}),e.jsx("p",{className:"text-[var(--text-secondary)] mb-4",children:s("developer.crossSchemaFk.configuration.intro")}),e.jsx(t,{title:s("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!
    }
}`})]}),e.jsxs("section",{className:"card p-6",children:[e.jsx("h2",{className:"text-xl font-bold mb-4",children:s("developer.crossSchemaFk.faq.title")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("h3",{className:"font-semibold mb-2",children:s("developer.crossSchemaFk.faq.question1")}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:s("developer.crossSchemaFk.faq.answer1")})]}),e.jsxs("div",{className:"p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("h3",{className:"font-semibold mb-2",children:s("developer.crossSchemaFk.faq.question2")}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:s("developer.crossSchemaFk.faq.answer2")})]}),e.jsxs("div",{className:"p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("h3",{className:"font-semibold mb-2",children:s("developer.crossSchemaFk.faq.question3")}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:s("developer.crossSchemaFk.faq.answer3")})]})]})]}),e.jsxs("div",{className:"flex justify-between pt-4 border-t border-[var(--border-color)]",children:[e.jsxs(a.Link,{to:"/system/docs/developer/dual-dbcontext",className:"flex items-center gap-2 text-[var(--color-primary-600)] hover:underline",children:[e.jsx(r.ArrowRight,{className:"w-4 h-4 rotate-180"}),s("developer.crossSchemaFk.navigation.prevPage")]}),e.jsxs(a.Link,{to:"/system/docs/developer/infrastructure",className:"flex items-center gap-2 text-[var(--color-primary-600)] hover:underline",children:[s("developer.crossSchemaFk.navigation.nextPage"),e.jsx(r.ArrowRight,{className:"w-4 h-4"})]})]})]})}exports.CrossSchemaFkPage=i;
//# sourceMappingURL=CrossSchemaFkPage-DqFNORYd.cjs.map
