// Shared types used by backend and admin-panel

export type UserRole = 'admin' | 'superuser' | 'user'

export interface User {
  id: string
  username: string
  email: string
  role: UserRole
  employeeId?: string | null
  lastLogin?: Date | null
  isActive: boolean
  createdAt: Date
  updatedAt: Date
}

export interface Skill {
  id: string
  name: string
  category?: string | null
  level?: string | null
  verified?: boolean
  verifiedBy?: string | null
  verifiedDate?: Date | null
}

export interface LanguageSkill {
  code: string
  level: 'basic' | 'fluent' | 'native' | 'business'
  certified?: boolean
  certificateType?: string | null
  isNative?: boolean
  canInterpret?: boolean
}

export interface Clearance {
  level: string
  validUntil: Date
  issuedDate: Date
}

export interface Employee {
  id: string
  firstName: string
  lastName: string
  employeeNumber: string
  photo?: string | null
  position: string
  officialTitle?: string | null
  department: string
  email?: string | null
  phone?: string | null
  mobile?: string | null
  office?: string | null
  availability: string
  skills?: Skill[]
  languages?: LanguageSkill[]
  clearance?: Clearance
  specializations?: string[]
  createdAt: Date | string
  updatedAt: Date | string
  createdBy?: string
  updatedBy?: string | null
}

export interface SkillDefinition {
  id: string
  name: string
  category?: string
  description?: string
}

export interface LoginRequest {
  username?: string
  email?: string
  password: string
}

export interface Token {
  accessToken: string
  expiresIn: number
  tokenType: 'Bearer'
}

export interface LoginResponse {
  user: User
  token: Token
}

export const ROLE_PERMISSIONS: Record<UserRole, string[]>

export const DEFAULT_SKILLS: Record<string, string[]>
export const LANGUAGE_LEVELS: string[]
export interface SkillLevel { id: string; name: string; level?: string }
export interface SubCategory { id: string; name: string; skills: SkillLevel[] }
export interface SkillCategory { id: string; name: string; subcategories: SubCategory[] }
export const SKILL_HIERARCHY: SkillCategory[]

// Workspaces
export type WorkspaceType = 'desk' | 'meeting_room' | 'phone_booth' | 'parking' | 'locker'

export interface Workspace {
  id: string
  name: string
  type: WorkspaceType
  floor: string
  building?: string | null
  capacity: number
  equipment: string[]
  position_x?: number | null
  position_y?: number | null
  is_active: boolean
  created_at: string
  updated_at: string
}

export interface WorkspaceFilter {
  type?: WorkspaceType
  floor?: string
  building?: string
  min_capacity?: number
}

// Organization
export type OrganizationalUnitType = 'direktion' | 'abteilung' | 'dezernat' | 'sachgebiet' | 'teildezernat' | 'fuehrungsstelle' | 'stabsstelle' | 'sondereinheit'
export type EmployeeUnitRole = 'leiter' | 'stellvertreter' | 'mitarbeiter' | 'beauftragter'

export interface OrganizationalUnit {
  id: string
  code: string
  name: string
  type: OrganizationalUnitType
  level: number
  parentId?: string | null
  positionX?: number | null
  positionY?: number | null
  color?: string | null
  orderIndex?: number
  description?: string | null
  hasFuehrungsstelle?: boolean
  fuehrungsstelleName?: string | null
  isActive?: boolean
  createdAt?: string
  updatedAt?: string
  children?: OrganizationalUnit[]
  employees?: any[]
}

export interface EmployeeUnitAssignment {
  id: string
  employeeId: string
  unitId: string
  role: EmployeeUnitRole
  startDate: string
  endDate?: string | null
  isPrimary: boolean
  createdAt: string
  updatedAt: string
}

export interface SpecialPosition {
  id: string
  employeeId: string
  positionType: string
  unitId?: string | null
  startDate: string
  endDate?: string | null
  isActive: boolean
  createdAt: string
  updatedAt: string
}

export interface DeputyAssignment {
  id: string
  principalId: string
  deputyId: string
  unitId?: string | null
  validFrom: string
  validUntil: string
  reason?: string | null
  canDelegate: boolean
  createdBy: string
  createdAt: string
  updatedAt: string
}

export interface DeputyDelegation {
  id: string
  originalAssignmentId: string
  fromDeputyId: string
  toDeputyId: string
  reason?: string | null
  delegatedAt: string
  createdAt: string
}

// Bookings (for workspace management)
export interface Booking {
  id: string
  workspaceId: string
  userId: string
  employeeId: string
  startTime: string
  endTime: string
  status: 'confirmed' | 'cancelled' | 'completed' | 'no_show'
  checkInTime?: string | null
  checkOutTime?: string | null
  notes?: string | null
  createdAt: string
  updatedAt: string
}

export interface BookingRequest {
  workspaceId: string
  startTime: string
  endTime: string
  notes?: string
}
