export * from "../evo-people/fb_collections";
import type {
  FirestoreDocumentReference,
  IFireDoc,
  IGeoPoint,
  ITag,
} from "../shared";

// Permissões para a empresa
export const EvoPeopleCompanyPermissions = {
  List: "evo_people_company_read",
  Get: "evo_people_company_read",
  Create: "evo_people_company_write",
  Update: "evo_people_company_write",
  Delete: "evo_people_company_write",
} as const;

export type EvoPeopleCompanyPermissions =
  (typeof EvoPeopleCompanyPermissions)[keyof typeof EvoPeopleCompanyPermissions];

// Permissões para o departamento
export const EvoPeopleDepartmentPermissions = {
  List: "evo_people_department_read",
  Get: "evo_people_department_read",
  Create: "evo_people_department_write",
  Update: "evo_people_department_write",
  Delete: "evo_people_department_write",
} as const;

export type EvoPeopleDepartmentPermissions =
  (typeof EvoPeopleDepartmentPermissions)[keyof typeof EvoPeopleDepartmentPermissions];

// Permissões para o funcionário
export const EvoPeopleEmployeePermissions = {
  List: "evo_people_employee_read",
  Get: "evo_people_employee_read",
  Create: "evo_people_employee_write",
  Update: "evo_people_employee_write",
  Delete: "evo_people_employee_write",
} as const;

export type EvoPeopleEmployeePermissions =
  (typeof EvoPeopleEmployeePermissions)[keyof typeof EvoPeopleEmployeePermissions];

// Permissões para o office
export const EvoPeopleOfficePermissions = {
  List: "evo_people_office_read",
  Get: "evo_people_office_read",
  Create: "evo_people_office_write",
  Update: "evo_people_office_write",
  Delete: "evo_people_office_write",
} as const;

export type EvoPeopleOfficePermissions =
  (typeof EvoPeopleOfficePermissions)[keyof typeof EvoPeopleOfficePermissions];

// ----- PeopleTypes

// Enum for EvoPeople Action - used in Activities tracking
export type PeopleAction =
  | "CREATE_COMPANY"
  | "DELETE_COMPANY"
  | "UPDATE_COMPANY"
  | "UPDATE_COMPANY_LEAD"
  | "UPDATE_COMPANY_NAME"
  | "CREATE_OFFICE"
  | "DELETE_OFFICE"
  | "UPDATE_OFFICE"
  | "UPDATE_OFFICE_NAME"
  | "UPDATE_OFFICE_TIMEZONE"
  | "UPDATE_OFFICE_COMPANY"
  | "UPDATE_OFFICE_LEAD"
  | "CREATE_DEPARTMENT"
  | "DELETE_DEPARTMENT"
  | "UPDATE_DEPARTMENT"
  | "UPDATE_DEPARTMENT_PARENT_DEPARTMENT"
  | "UPDATE_DEPARTMENT_LEAD"
  | "UPDATE_DEPARTMENT_NAME"
  | "CREATE_EMPLOYEE"
  | "DELETE_EMPLOYEE"
  | "UPDATE_EMPLOYEE"
  | "UPDATE_EMPLOYEE_PHOTO"
  | "UPDATE_PROFILE"
  | "UPDATE_PHOTO"
  | "UPDATE_PASSWORD"
  | "UPDATE_EMPLOYEE_REPORT_TO"
  | "UPDATE_EMPLOYEE_DEPARTMENT"
  | "UPDATE_EMPLOYEE_OFFICE"
  | "UPDATE_EMPLOYEE_COMPANY"
  | "UPDATE_EMPLOYEE_JOB_TITLE"
  | "UPDATE_EMPLOYEE_WORK_EMAIL"
  | "UPDATE_EMPLOYEE_STATUS";

export enum IPeopleAction {
  Create_company = "CREATE_COMPANY",
  Delete_company = "DELETE_COMPANY",
  Update_company = "UPDATE_COMPANY",
  Update_company_lead = "UPDATE_COMPANY_LEAD",
  Update_company_name = "UPDATE_COMPANY_NAME",
  Create_office = "CREATE_OFFICE",
  Delete_office = "DELETE_OFFICE",
  Update_office = "UPDATE_OFFICE",
  Update_office_name = "UPDATE_OFFICE_NAME",
  Update_office_timezone = "UPDATE_OFFICE_TIMEZONE",
  Update_office_company = "UPDATE_OFFICE_COMPANY",
  Update_office_lead = "UPDATE_OFFICE_LEAD",
  Create_department = "CREATE_DEPARTMENT",
  Delete_department = "DELETE_DEPARTMENT",
  Update_department = "UPDATE_DEPARTMENT",
  Update_department_parent_department = "UPDATE_DEPARTMENT_PARENT_DEPARTMENT",
  Update_department_lead = "UPDATE_DEPARTMENT_LEAD",
  Update_department_name = "UPDATE_DEPARTMENT_NAME",
  Create_employee = "CREATE_EMPLOYEE",
  Delete_employee = "DELETE_EMPLOYEE",
  Update_employee = "UPDATE_EMPLOYEE",
  Update_employee_photo = "UPDATE_EMPLOYEE_PHOTO",
  Update_profile = "UPDATE_PROFILE",
  Update_photo = "UPDATE_PHOTO",
  Update_password = "UPDATE_PASSWORD",
  Update_employee_report_to = "UPDATE_EMPLOYEE_REPORT_TO",
  Update_employee_department = "UPDATE_EMPLOYEE_DEPARTMENT",
  Update_employee_office = "UPDATE_EMPLOYEE_OFFICE",
  Update_employee_company = "UPDATE_EMPLOYEE_COMPANY",
  Update_employee_job_title = "UPDATE_EMPLOYEE_JOB_TITLE",
  Update_employee_work_email = "UPDATE_EMPLOYEE_WORK_EMAIL",
  Update_employee_status = "UPDATE_EMPLOYEE_STATUS",
}

// PeopleTypes
export type EmployeeStatus = "active" | "inactive" | "draft";
export enum IEmployeeStatus {
  Active = "active",
  Inactive = "inactive",
  Draft = "draft",
}

export interface IEmployeeCounters {
  active: number;
  inactive: number;
  draft: number;
  deleted: number;
  total: number;
}

export interface IProfile extends IFireDoc {
  display_name: string;
  last_name?: string | null;
  first_name?: string | null;
  gender?: string | null;
  birthdate?: Date | null;
  photo_ref?: string | null;
  photo_url?: string | null;
}

export interface IEmployee extends IProfile {
  employeeId?: string | null;
  type?: string | null;
  job_title?: string | null;
  status?: EmployeeStatus;
  company_name?: string | null;
  companyRef?: FirestoreDocumentReference;
  date_joining?: Date | null;
  reporting_to_name?: string | null;
  reporting_toRef?: FirestoreDocumentReference;
  department_name?: string | null;
  departmentRef?: FirestoreDocumentReference;
  office_name?: string | null;
  officeRef?: FirestoreDocumentReference;
  work_email?: string | null;
  work_phone?: string | null;
  work_mobile?: string | null;
  tags?: ITag[] | null;
  userRef?: FirestoreDocumentReference;
  [key: string]: unknown; // index signature
}

export interface IDepartment extends IFireDoc {
  code: string;
  name: string;
  lead_name?: string | null;
  leadRef?: FirestoreDocumentReference;
  parent_department_name?: string | null;
  parent_departmentRef?: FirestoreDocumentReference | null;
  readonly employee_counters?: IEmployeeCounters;
  tags?: ITag[] | null;

  /** Must be explicitly true for the department to receive chat transfers and be used as channel default. */
  chat_enabled?: boolean | null;
  /** Color for UI rendering in hub-omni (e.g., '#4CAF50'). */
  chat_color?: string | null;
}

export interface IOffice extends IFireDoc {
  code: string;
  name: string;
  timezone?: string | null;
  company_name?: string | null;
  companyRef?: FirestoreDocumentReference;
  lead_name?: string | null;
  leadRef?: FirestoreDocumentReference;
  address_line1?: string;
  address_line2?: string;
  address_city?: string;
  address_state?: string;
  address_zip?: string;
  address_country?: string;
  address_neighborhood?: string;
  address_maps_url?: string;
  address_notes?: string;
  address_geo?: IGeoPoint;
  readonly employee_counters?: IEmployeeCounters;
  tags?: ITag[] | null;
}

export interface ICompany extends IFireDoc {
  code: string;
  name: string;
  lead_name?: string | null;
  leadRef?: FirestoreDocumentReference;
  readonly employee_counters?: IEmployeeCounters;
  tags?: ITag[] | null;
  [key: string]: unknown; // index signature
}
