export type AllocationDragStateLike<TMode extends string = string, TScope extends string = string> = {
  isActive: boolean;
  mode: TMode;
  scope: TScope;
  allocationId: string | null;
  mutationAllocationId: string | null;
  projectId: string | null;
  projectName: string | null;
  resourceId: string | null;
  allocationStartDate: Date | null;
  allocationEndDate: Date | null;
  originalStartDate: Date | null;
  originalEndDate: Date | null;
  currentStartDate: Date | null;
  currentEndDate: Date | null;
  startMouseX: number;
  pointerDeltaX: number;
  daysDelta: number;
};

type CreateAllocationDragStateInput<TMode extends string, TScope extends string> = {
  mode: TMode;
  scope?: TScope | undefined;
  allocationId: string;
  mutationAllocationId?: string | undefined;
  projectId: string;
  projectName: string;
  resourceId: string | null;
  startDate: Date;
  endDate: Date;
  allocationStartDate?: Date | undefined;
  allocationEndDate?: Date | undefined;
  startMouseX: number;
};

export function createAllocationDragState<
  TState extends AllocationDragStateLike<TMode, TScope>,
  TMode extends string,
  TScope extends string,
>(input: CreateAllocationDragStateInput<TMode, TScope>): TState {
  return {
    isActive: true,
    mode: input.mode,
    scope: input.scope ?? ("allocation" as TScope),
    allocationId: input.allocationId,
    mutationAllocationId: input.mutationAllocationId ?? input.allocationId,
    projectId: input.projectId,
    projectName: input.projectName,
    resourceId: input.resourceId,
    allocationStartDate: input.allocationStartDate ?? input.startDate,
    allocationEndDate: input.allocationEndDate ?? input.endDate,
    originalStartDate: input.startDate,
    originalEndDate: input.endDate,
    currentStartDate: input.startDate,
    currentEndDate: input.endDate,
    startMouseX: input.startMouseX,
    pointerDeltaX: 0,
    daysDelta: 0,
  } as TState;
}
