/**
 * Users store actions using `createActionGroup`.
 */
import {
  createActionGroup,
  emptyProps,
  props
} from '@ngrx/store';
import {
  User,
  UserStatus,
  BanEntry,
  VoiceState,
  ScreenShareState,
  CameraState,
  GameActivity
} from '../../shared-kernel';

export const UsersActions = createActionGroup({
  source: 'Users',
  events: {
    'Authenticate User': props<{ user: User }>(),
    'Load Current User': emptyProps(),
    'Load Current User Success': props<{ user: User }>(),
    'Load Current User Failure': props<{ error: string }>(),

    'Set Current User': props<{ user: User }>(),
    'Update Current User': props<{ updates: Partial<User> }>(),

    'Load Room Users': props<{ roomId: string }>(),
    'Load Room Users Success': props<{ users: User[] }>(),
    'Load Room Users Failure': props<{ error: string }>(),

    'User Joined': props<{ user: User }>(),
    'User Left': props<{ userId: string; serverId?: string; serverIds?: string[] }>(),
    'Sync Server Presence': props<{ roomId: string; users: User[]; connectedPeerIds?: string[] }>(),

    'Update User': props<{ userId: string; updates: Partial<User> }>(),
    'Update User Role': props<{ userId: string; role: User['role'] }>(),

    'Kick User': props<{ userId: string; roomId?: string }>(),
    'Kick User Success': props<{ userId: string; roomId: string }>(),

    'Ban User': props<{
      userId: string;
      roomId?: string;
      displayName?: string;
      reason?: string;
      expiresAt?: number;
    }>(),
    'Ban User Success': props<{ userId: string; roomId: string; ban: BanEntry }>(),
    'Unban User': props<{ roomId: string; oderId: string }>(),
    'Unban User Success': props<{ oderId: string }>(),

    'Load Bans': emptyProps(),
    'Load Bans Success': props<{ bans: BanEntry[] }>(),

    'Admin Mute User': props<{ userId: string }>(),
    'Admin Unmute User': props<{ userId: string }>(),

    'Sync Users': props<{ users: User[] }>(),
    'Clear Users': emptyProps(),
    'Reset Users State': emptyProps(),
    'Update Host': props<{ userId: string }>(),

    'Update Voice State': props<{ userId: string; voiceState: Partial<VoiceState> }>(),
    'Update Screen Share State': props<{ userId: string; screenShareState: Partial<ScreenShareState> }>(),
    'Update Camera State': props<{ userId: string; cameraState: Partial<CameraState> }>(),
    'Update Game Activity': props<{ userId: string; gameActivity: GameActivity | null }>(),

    'Set Manual Status': props<{ status: UserStatus | null }>(),
    'Update Remote User Status': props<{ userId: string; status: UserStatus }>(),

    'Update Current User Profile': props<{
      profile: {
        displayName: string;
        description?: string;
        profileUpdatedAt: number;
      };
    }>(),
    'Update Current User Avatar': props<{
      avatar: {
        avatarUrl: string;
        avatarHash: string;
        avatarMime: string;
        avatarUpdatedAt: number;
      };
    }>(),
    'Upsert Remote User Avatar': props<{
      user: {
        id: string;
        oderId: string;
        username: string;
        displayName: string;
        description?: string;
        profileUpdatedAt?: number;
        avatarUrl?: string;
        avatarHash?: string;
        avatarMime?: string;
        avatarUpdatedAt?: number;
      };
    }>()
  }
});
