export type EventType = 'clock_in' | 'clock_out' | 'break_start' | 'break_end';
export type LiveStatus = 'clocked_out' | 'working' | 'on_break';
export type Role = 'admin' | 'employee';

export interface SessionUser {
  email: string;
  name: string | null;
  role: Role;
  employeeId: number | null;
}

export interface Employee {
  id: number;
  email: string;
  name: string | null;
  active: 0 | 1;
  created_at: string;
}

export interface AttendanceEvent {
  id: number;
  employee_id: number;
  type: EventType;
  ts: string;
}

export interface Session {
  clockIn: string;
  clockOut: string | null;
  breaks: { start: string; end: string | null }[];
  workedMs: number;
  breakMs: number;
  open: boolean;
}

export interface StatsSummary {
  range: { from: string; to: string };
  sessions: Session[];
  totalWorkedMs: number;
  totalBreakMs: number;
  shiftCount: number;
}

export interface EmployeeStat {
  employee: Employee;
  totalWorkedMs: number;
  totalBreakMs: number;
  shiftCount: number;
}

export interface AdminStatsSummary {
  range: { from: string; to: string };
  totals: { totalWorkedMs: number; totalBreakMs: number; shiftCount: number };
  employees: EmployeeStat[];
}

export type ShiftSlotStatus = 'open' | 'full' | 'closed';

export interface AvailableShiftSlot {
  slot_id: number;
  date: string;
  start_time: string;
  end_time: string;
  capacity: number;
  occupied: number;
  free_places: number;
  note: string;
}

export interface MyShiftSlot {
  signup_id: number;
  slot_id: number;
  date: string;
  start_time: string;
  end_time: string;
  note: string;
}

export interface AdminShiftSlot {
  id: number;
  date: string;
  start_time: string;
  end_time: string;
  capacity: number;
  status: ShiftSlotStatus;
  note: string;
  generated: boolean;
  occupied: number;
  employees: { employee_id: number; name: string }[];
}

export interface EmployeeWithRate extends Employee {
  hourly_rate: number;
}

export type ClosureStatus = 'waiting_employee' | 'confirmed' | 'locked';

export interface MonthClosure {
  id: number;
  employee_id: number;
  period: string;
  status: ClosureStatus;
  employee_confirmed_at: string | null;
  locked_at: string | null;
}

export interface ClosureSummary {
  worked_minutes: number;
  shift_count: number;
  earned_estimate: number;
}

export type PayrollStatus = 'draft' | 'ready' | 'paid';

export interface Payroll {
  id: number;
  employee_id: number;
  period: string;
  worked_minutes: number;
  base_amount: number;
  tips_amount: number;
  bonus_amount: number;
  other_amount: number;
  final_amount: number;
  status: PayrollStatus;
  payment_date: string | null;
  updated_at: string;
}

export interface PayrollOverviewRow {
  employee_id: number;
  employee_name: string;
  closure_status: ClosureStatus;
  worked_minutes: number;
  base_amount: number;
  tips_amount: number;
  bonus_amount: number;
  other_amount: number;
  final_amount: number;
  payroll_status: PayrollStatus | null;
  payment_date: string | null;
}
