import { type User } from 'src/types/user';

export const SortingOptions = {
  LAST_UPDATE_ASC: 'LAST_UPDATE_ASC',
  TITLE_ASC: 'TITLE_ASC',
  LAST_UPDATE_DESC: 'LAST_UPDATE_DESC',
  TITLE_DESC: 'TITLE_DESC',
} as const;

export const TableColumns = {
  title: 'title',
  lastModified: 'lastModified',
  createdAt: 'createdAt',
} as const;

export const SortingOrder = {
  ASC: 'ASC',
  DESC: 'DESC_NULLS_LAST',
} as const;

export type SortingOptionsType =
  (typeof SortingOptions)[keyof typeof SortingOptions];

export type TableColumnsType = (typeof TableColumns)[keyof typeof TableColumns];

export type SortingOrderType = (typeof SortingOrder)[keyof typeof SortingOrder];

// New audience endpoint types
export type SegmentationCondition = {
  type: SegmentationConditionType;
  segmentationItemIds?: number[];
  userIds?: number[];
  operator?: SegmentationOperatorType;
  expressions?: SegmentationCondition[];
};

export type LearningDuration = {
  hours: number;
  minutes: number;
} | null;

const SegmentationCondition = {
  USERS_OR_ITEMS: 'USERS_OR_ITEMS',
  ALL: 'ALL',
  USERS: 'USERS',
  ITEMS: 'ITEMS',
  EXPRESSION: 'EXPRESSION',
} as const;

const SegmentationOperator = {
  AND: 'AND',
  OR: 'OR',
} as const;

export type SegmentationConditionType =
  (typeof SegmentationCondition)[keyof typeof SegmentationCondition];

export type SegmentationOperatorType =
  (typeof SegmentationOperator)[keyof typeof SegmentationOperator];

export type SegmentationPayload = {
  segmentationExpressions: {
    conditions: SegmentationCondition[];
  };
};

export type LearningSegmentation = {
  userSegmentation: Pick<User, 'id' | 'firstName' | 'lastName'>[];
  groupSegmentation: number[];
};

export type SessionsAudienceResponse = {
  conditions: (Omit<SegmentationCondition, 'userIds'> & {
    users: LearningSegmentation['userSegmentation'];
  })[];
};

export type LearningAudience = {
  isAudienceDefined: boolean;
  isPublic: boolean;
  segmentationItemIds: number[];
  segmentationUsers: LearningSegmentation['userSegmentation'];
};
