import type { SupabaseOrgMembership, SupabaseMembershipWithOrganization } from '../../supabase'
import { TEST_USERS } from './users'
import { TEST_ORGS } from './organizations'

/**
 * Test membership fixtures using actual Supabase types
 */
export const TEST_MEMBERSHIPS: Record<string, SupabaseOrgMembership> = {
  regularUserAcme: {
    id: '00000000-0000-0000-0000-000000000020',
    user_id: TEST_USERS.regularUser.id,
    organization_id: TEST_ORGS.acme.id,
    workos_membership_id: 'mem_regular_acme',
    role_slug: 'admin',
    membership_status: 'active',
    config: {},
    effective_permissions: [],
    created_at: '2025-01-01T00:00:00Z',
    updated_at: '2025-01-01T00:00:00Z'
  },
  regularUserBeta: {
    id: '00000000-0000-0000-0000-000000000021',
    user_id: TEST_USERS.regularUser.id,
    organization_id: TEST_ORGS.beta.id,
    workos_membership_id: 'mem_regular_beta',
    role_slug: 'member',
    membership_status: 'active',
    config: {},
    effective_permissions: [],
    created_at: '2025-01-01T00:00:00Z',
    updated_at: '2025-01-01T00:00:00Z'
  },
  inactiveUserAcme: {
    id: '00000000-0000-0000-0000-000000000022',
    user_id: TEST_USERS.inactiveUser.id,
    organization_id: TEST_ORGS.acme.id,
    workos_membership_id: 'mem_inactive_acme',
    role_slug: 'member',
    membership_status: 'inactive',
    config: {},
    effective_permissions: [],
    created_at: '2025-01-01T00:00:00Z',
    updated_at: '2025-01-01T00:00:00Z'
  }
}

/**
 * Composite memberships with organization data (for joined queries)
 */
export const TEST_MEMBERSHIPS_WITH_ORG: Record<string, SupabaseMembershipWithOrganization> = {
  regularUserAcme: {
    ...TEST_MEMBERSHIPS.regularUserAcme,
    organization: TEST_ORGS.acme
  },
  regularUserBeta: {
    ...TEST_MEMBERSHIPS.regularUserBeta,
    organization: TEST_ORGS.beta
  },
  inactiveUserAcme: {
    ...TEST_MEMBERSHIPS.inactiveUserAcme,
    organization: TEST_ORGS.acme
  }
}

/**
 * Helper to create custom membership fixture
 */
export function createTestMembership(overrides: Partial<SupabaseOrgMembership>): SupabaseOrgMembership {
  return {
    id: '00000000-0000-0000-0000-999999999999',
    user_id: TEST_USERS.regularUser.id,
    organization_id: TEST_ORGS.acme.id,
    workos_membership_id: 'mem_custom_test',
    role_slug: 'member',
    membership_status: 'active',
    config: {},
    effective_permissions: [],
    created_at: '2025-01-01T00:00:00Z',
    updated_at: '2025-01-01T00:00:00Z',
    ...overrides
  }
}
