export type ApiUserRole = 'Student' | 'Teacher' | 'Admin'
export type ApiLectureFormat = 'Online' | 'Offline'
export type ApiReviewRating = 'Like' | 'Neutral' | 'Dislike'
export type ApiReviewLlmStatus = 'Pending' | 'Analyzed' | 'Rejected'
export type ApiReviewSentiment = 'Positive' | 'Neutral' | 'Negative'
export type ApiCoinTransactionType =
  | 'ReviewReward'
  | 'AchievementReward'
  | 'AttendanceReward'
  | 'AdminAdjustment'

export interface PagedResult<T> {
  items: T[]
  totalCount: number
  page: number
  pageSize: number
  totalPages: number
}

export interface AuthResponse {
  accessToken: string
  expiresAt: string
  user: UserAuthDto
}

export interface LoginMicrosoftRequest {
  authorizationCode: string
  redirectUri?: string
}

export interface UserAuthDto {
  id: number
  email: string
  displayName?: string | null
  roles: ApiUserRole[]
}

export interface UserDto extends UserAuthDto {
  id: number
  avatarUrl?: string | null
  isActive: boolean
  xp: number
  coins: number
  level: number
  createdAt: string
}

export interface CurrentUserDto extends UserAuthDto {
  avatarUrl?: string | null
  xp: number
  coins: number
  level: number
  createdAt: string
}

export interface UserQuery {
  Search?: string
  Role?: ApiUserRole
  IsActive?: boolean
  Page?: number
  PageSize?: number
}

export interface UserStatsDto {
  totalLectures: number
  attendedLectures: number
  totalReviews: number
  xp: number
  coins: number
  level: number
  achievementsCount: number
  currentLevelXp: number
  nextLevelXp?: number | null
  activeEnrollments: number
  enrollmentSlotLimit: number
  enrollmentSlotRules: EnrollmentSlotRuleDto[]
}

export interface AdminDashboardStatsDto {
  usersCount: number
  lecturesCount: number
  enrollmentsCount: number
  pendingReviewsCount: number
}

export interface CalendarSubscriptionDto {
  feedUrl: string
}

export interface EnrollmentSlotRuleDto {
  level: number
  slots: number
}

export interface LectureDto {
  id: number
  courseId: number
  courseName?: string | null
  teacherId?: number | null
  teacherName?: string | null
  locationId?: number | null
  locationName?: string | null
  title?: string | null
  description?: string | null
  format: ApiLectureFormat
  startsAt: string
  endsAt: string
  isOpen: boolean
  maxEnrollments: number
  enrollmentsCount: number
  onlineUrl?: string | null
  createdAt: string
  isEnrolled?: boolean
}

export interface CreateLectureRequest {
  courseId: number
  teacherId?: number | null
  locationId?: number | null
  title: string
  description?: string | null
  format: ApiLectureFormat
  startsAt: string
  endsAt: string
  isOpen: boolean
  maxEnrollments: number
  onlineUrl?: string | null
}

export interface ReviewQuery {
  LlmStatus?: ApiReviewLlmStatus
  Page?: number
  PageSize?: number
}

export interface ReviewDto {
  id: number
  lectureId: number
  lectureTitle?: string | null
  userId: number
  userName?: string | null
  rating: ApiReviewRating
  text?: string | null
  llmStatus: ApiReviewLlmStatus
  sentiment?: ApiReviewSentiment | null
  qualityScore?: number | null
  isInformative?: boolean | null
  llmTags?: string[] | null
  llmRawOutput?: string | null
  createdAt: string
}

export interface ReviewPromptDto {
  prompt: string
  updatedAt?: string | null
}

export interface UpdateReviewPromptRequest {
  prompt: string
}

export interface AchievementDto {
  id: number
  name?: string | null
  description?: string | null
  iconUrl?: string | null
  xpReward: number
  coinReward: number
  condition?: string | null
  createdAt: string
}

export interface CourseDto {
  id: number
  name?: string | null
  description?: string | null
  isSynced: boolean
  tags?: TagDto[] | null
  createdAt: string
}

export interface LocationDto {
  id: number
  name?: string | null
  building?: string | null
  room?: string | null
  address?: string | null
  createdAt: string
}

export type ApiTagType = 'Institute' | 'Faculty' | 'Subject' | 'Organization' | 'Topic' | 'Other'

export interface TagDto {
  id: number
  name?: string | null
  type: ApiTagType
  parentId?: number | null
  createdAt: string
}

export interface SyncStatusDto {
  lastSyncAt?: string | null
  status?: string | null
  lastResult?: SyncResultDto | null
}

export type ApiScheduleTypeId =
  | 'MID_CHECK'
  | 'CONS'
  | 'LAB'
  | 'LECT'
  | 'SEMI'
  | 'EVENT_OTHER'
  | 'SELF'
  | 'CUR_CHECK'

export interface SyncScheduleRequest {
  size: number
  timeMin?: string | null
  timeMax?: string | null
  roomId?: string[] | null
  attendeePersonId?: string[] | null
  courseUnitRealizationId?: string[] | null
  cycleRealizationId?: string[] | null
  specialtyCode?: string[] | null
  learningStartYear?: number[] | null
  profileName?: string[] | null
  curriculumId?: string[] | null
  typeId?: ApiScheduleTypeId[] | null
}

export interface SyncResultDto {
  created: number
  updated: number
  skipped: number
  error?: string | null
  details?: string[] | null
}

export interface UserAchievementDto {
  id: number
  achievement: AchievementDto
  awardedAt: string
}

export interface CoinTransactionDto {
  id: number
  amount: number
  type: ApiCoinTransactionType
  reviewId?: number | null
  achievementId?: number | null
  description?: string | null
  createdAt: string
}

export interface UserNotificationDto {
  id: number
  type: 'reminder' | 'schedule-change' | 'achievement' | 'coins' | 'recommendation'
  title: string
  body: string
  isRead: boolean
  createdAt: string
}

export interface LectureQuery {
  DateFrom?: string
  DateTo?: string
  CourseId?: number
  TeacherId?: number
  Format?: ApiLectureFormat
  IsOpen?: boolean
  TagId?: number
  Search?: string
  Page?: number
  PageSize?: number
}
