import 'package:flutter_test/flutter_test.dart';
import 'package:tdc114plus/src/features/directory/presentation/directory_navigation.dart';
import 'package:tdc114plus/src/features/organization/domain/organization_models.dart';

void main() {
  const tenants = [
    TenantSummary(
      id: 'company-a',
      name: '총괄기획실/기술',
      slug: 'hq-tech',
      type: 'COMPANY',
      memberCount: 10,
      totalMemberCount: 50,
    ),
    TenantSummary(
      id: 'company-b',
      name: '바른컨설턴트',
      slug: 'consulting',
      type: 'COMPANY',
      memberCount: 5,
      totalMemberCount: 20,
    ),
    TenantSummary(
      id: 'team-is3',
      name: 'IS3',
      slug: 'is3',
      type: 'ORGANIZATION',
      parentId: 'company-a',
      memberCount: 3,
      totalMemberCount: 3,
    ),
    TenantSummary(
      id: 'team-ptc',
      name: 'PTC',
      slug: 'ptc',
      type: 'ORGANIZATION',
      parentId: 'company-a',
      memberCount: 2,
      totalMemberCount: 2,
    ),
  ];

  test('shows pinned team chip for selected company', () {
    final layout = buildTenantNavigationModel(
      tenants: tenants,
      selectedTenantSlug: 'hq-tech',
      pinnedTenantSlug: 'is3',
    );

    expect(layout.companyTenants.map((tenant) => tenant.slug), [
      'hq-tech',
      'consulting',
    ]);
    expect(layout.visibleChips.map((tenant) => tenant.slug), [
      'hq-tech',
      'consulting',
      'is3',
    ]);
  });

  test('builds breadcrumb and child tenants for selected child team', () {
    final layout = buildTenantNavigationModel(
      tenants: tenants,
      selectedTenantSlug: 'is3',
      pinnedTenantSlug: 'is3',
    );

    expect(layout.selectedTenant?.slug, 'is3');
    expect(layout.breadcrumbTenants.map((tenant) => tenant.slug), [
      'hq-tech',
      'is3',
    ]);
    expect(layout.childTenants, isEmpty);
  });

  test('shows company drilldown for all selection', () {
    final layout = buildTenantNavigationModel(
      tenants: tenants,
      selectedTenantSlug: 'all',
      pinnedTenantSlug: 'is3',
    );

    expect(layout.selectedTenant, isNull);
    expect(layout.childTenants.map((tenant) => tenant.slug), [
      'hq-tech',
      'consulting',
    ]);
    expect(layout.visibleChips.map((tenant) => tenant.slug), [
      'hq-tech',
      'consulting',
      'is3',
    ]);
  });

  test('builds selected tenant subtree slugs for scoped search', () {
    final layout = buildTenantNavigationModel(
      tenants: tenants,
      selectedTenantSlug: 'hq-tech',
      pinnedTenantSlug: 'is3',
    );

    expect(layout.selectedTenantSubtreeSlugs, ['hq-tech', 'is3', 'ptc']);
  });

  test('resolves pinned team slug from company and department name', () {
    final slug = resolvePinnedTenantSlug(
      tenants: tenants,
      companySlug: 'hq-tech',
      departmentName: 'IS3',
    );

    expect(slug, 'is3');
  });
}
