import { type ServiceItemFilterValue } from './serviceItem';
import { type State, type StateFilterValue } from './state';

type UserParam = {
  id: number;
  firstName: string;
  lastName: string;
  profilePicture: string | null;
  employeeInternalId: string;
};

type ServiceItemsParam = {
  id: string;
  name: string;
};

// Form values shared between the agent workspace ticket drawer filters and
// the saved views form. Lives in the shared types/ directory (rather than
// agentWorkspace/types.ts) to avoid a barrel-induced circular dependency
// with task.ts.
export type FilterFormValues = {
  statesIn: (State & { title: string })[];
  serviceItemsIn: ServiceItemsParam[];
  creationDateFrom: Date | null;
  creationDateTo: Date | null;
  initiatorsIn: UserParam[];
  initiatorCollaboratorTypesIn: any[];
  agentsIn: UserParam[];
};

export type ViewForm = FilterFormValues & { name: string };

export type ViewData = {
  id: string;
  ownerId: number;
  instanceId: number;
  name: string;
  createdAt: string;
  updatedAt: string;
  position: number;
};

export type InitiatorFilterValue = {
  id: number;
  employeeInternalId: string;
  firstName: string;
  lastName: string;
  profilePicture: string;
  email: string;
};

export type AssigneeFilterValue = {
  id: number;
  employeeInternalId: string;
  firstName: string;
  lastName: string;
  profilePicture: string;
  email: string;
};

export type TaskFiltersHydrated = {
  catalogItemsIn: ServiceItemFilterValue[];
  statesIn: StateFilterValue[];
  createdAtFrom: string;
  createdAtTo: string;
  initiatorsIn: InitiatorFilterValue[];
  assigneesIn: AssigneeFilterValue[];
  initiatorSegmentations: Record<string, number[]> | null;
};

export type TaskFiltersUnhydrated = {
  stateIn: string[];
  catalogItemsIn: string[];
  createdAtFrom: string;
  createdAtTo: string;
  initiatorsIn: number[];
  assigneesIn: number[];
  initiatorSegmentations: string;
};

export type ViewListItem = ViewData & {
  filters: TaskFiltersUnhydrated;
};

export type View = ViewData & {
  filters: TaskFiltersHydrated;
};
