// src/shared/contracts/personnel.ts
// Personnel contracts - centralized types for employee management

/**
 * Employment period for tracking employee work history
 */
export interface EmploymentPeriod {
  id: string;
  userId: string;
  startDate: string; // YYYY-MM-DD format
  endDate: string | null; // YYYY-MM-DD format or null if still employed
  isMaid: boolean; // true for maid role, false for manager role
  createdAt: string; // ISO datetime string
}

/**
 * Maid period for tracking employee's maid role history
 */
export interface MaidPeriod {
  id: string;
  startDate: string; // YYYY-MM-DD format
  endDate: string | null; // YYYY-MM-DD format or null
}

/**
 * Simplified user type for schedule grid display
 */
export interface ScheduleUser {
  id: string;
  username: string;
  firstName: string;
  lastName: string;
  fullName: string;
  email: string | null;
  role: 'ADMIN' | 'MANAGER' | 'MAID' | 'GOD';
  isMaidAlso: boolean;
}

/**
 * Input for creating a new employee
 */
export interface EmployeeInput {
  fullName: string;
  position: string;
  phone: string;
  email: string | null;
  birthDate: string | null;
  address: string | null;
  notes: string | null;
  hireDate?: string; // Дата приёма (ISO datetime string)
  username?: string;
  password?: string;
  role?: string;
  maidPeriods?: Array<{
    id?: string;
    startDate: string; // YYYY-MM-DD format
    endDate?: string | null; // YYYY-MM-DD format or null
  }>;
}

/**
 * Input for updating an existing employee
 */
export interface EmployeeUpdate {
  fullName?: string;
  position?: string;
  phone?: string;
  email?: string | null;
  birthDate: string | null;
  address: string | null;
  notes: string | null;
  hireDate?: string; // Дата приёма (ISO datetime string)
  password?: string;
  role?: string;
  firedReason?: string | null;
  isFired?: boolean;
  archivedAt?: string | null; // Termination date (ISO datetime string)
  maidPeriods?: Array<{
    id?: string;
    startDate: string; // YYYY-MM-DD format
    endDate?: string | null; // YYYY-MM-DD format or null
    _deleted?: boolean; // Flag to mark period for deletion
  }>;
}

/**
 * Input for rehiring an employee
 */
export interface RehireEmployeeInput {
  returnReason: string;
  rehireDate?: string;
  maidPeriods?: Array<{
    id?: string;
    startDate: string; // YYYY-MM-DD format
    endDate?: string | null; // YYYY-MM-DD format or null
  }>;
}

/**
 * Employee response DTO
 */
export interface Employee {
  id: string;
  fullName: string;
  position: string;
  phone: string;
  email: string | null;
  birthDate: string | null;
  address: string | null;
  notes: string | null;
  isFired: boolean;
  firedReason: string | null;
  username: string | null;
  passwordHash: string | null;
  role: string | null;
  isMaidAlso: boolean; // Computed field - true if employee has active maid period today
  maidPeriods: MaidPeriod[]; // Array of all maid periods
  createdAt: string;
  updatedAt: string;
  archivedAt: string | null;
}
