import type { EntityStatus } from "@/shared/types";

export interface User {
  id: number;
  first_name: string;
  last_name: string;
  full_name: string;
  email: string;
  phone: string;
  status: EntityStatus;
  role: string | null;
  company_name: string;
  email_verified: boolean;
  created_at: string;
  profile_picture: string | null;
}

export interface UserDetail extends User {
  name: string;
  title: string | null;
  role_name: string;
  company_id: number | null;
  email_verified_at: string | null;
  address: string | null;
  city: string | null;
  postal_code: string | null;
  preferred_language: string | null;
  enable_2fa: boolean;
  email_notifications_enabled: boolean;
  push_notifications_enabled: boolean;
  updated_at: string;
}

export interface UserStats {
  total: number;
  active: number;
  disabled: number;
  email_verified: number;
}

export interface CreateUserPayload {
  first_name: string;
  last_name: string;
  email: string;
  phone: string;
  password: string;
  role: string;
  user_id?: number;
  status?: string;
}

export interface UpdateUserPayload {
  first_name?: string;
  last_name?: string;
  email?: string;
  phone?: string;
  role?: string;
  preferred_language?: string;
}

/** One permission of the user, `added` when granted to them on top of their role. */
export interface UserAccessAction {
  code: string;
  action: string;
  added: boolean;
}

export interface UserAccessModule {
  module: string;
  features: { feature: string; actions: UserAccessAction[] }[];
}

/** A client user's access, as the auth service grants it. */
export interface UserAccess {
  user: { id: number; name: string | null; email: string };
  company: { id: number; name: string | null } | null;
  role: { id: number; name: string; code: string; is_system: boolean } | null;
  /** Effective permissions: the role's, minus `removed`, plus the ones added to the user. */
  permissions: UserAccessModule[];
  /** Permissions of the role taken away from this user. */
  removed: UserAccessModule[];
  sites: { full_access: boolean; items: { id: number; name: string | null; archived: boolean }[] };
  /** Sees every company of its group. */
  group_view: boolean;
}
