import { createAction, props } from '@ngrx/store';
import {
  BuddyRequest,
  GroupRequest,
  GroupDetailData,
  GroupResponse,
  UserInfo,
  RoomRequest
} from '@ucap-webmessenger/protocol-sync';
import {
  RoomInfo,
  UserInfoShort,
  UserInfo as RoomUserInfo,
  InfoRequest
} from '@ucap-webmessenger/protocol-room';
import { Info, EventJson } from '@ucap-webmessenger/protocol-event';
import {
  AddResponse as GroupAddResponse,
  UpdateRequest as GroupUpdateRequest,
  UpdateResponse as GroupUpdateResponse,
  DelRequest as GroupDelRequest,
  DelResponse as GroupDelResponse
} from '@ucap-webmessenger/protocol-group';
import {
  AddRequest as BuddyAddRequest,
  AddResponse as BuddyAddResponse,
  DelRequest as BuddyDelRequest,
  DelResponse as BuddyDelResponse,
  UpdateRequest as BuddyUpdateRequest,
  UpdateResponse as BuddyUpdateResponse
} from '@ucap-webmessenger/protocol-buddy';

export const buddy2 = createAction(
  '[Messenger::Sync] Buddy2',
  props<BuddyRequest>()
);

export const buddy2Success = createAction(
  '[Messenger::Sync] Buddy2 Success',
  props<{ buddyList: UserInfo[]; syncDate: string }>()
);

export const buddy2Failure = createAction(
  '[Messenger::Sync] Buddy2 Failure',
  props<{ error: any }>()
);

export const group2 = createAction(
  '[Messenger::Sync] Group2',
  props<GroupRequest>()
);

export const group2Success = createAction(
  '[Messenger::Sync] Group2 Success',
  props<{ groupList: GroupDetailData[]; syncDate: string }>()
);

export const group2Failure = createAction(
  '[Messenger::Sync] Group2 Failure',
  props<{ error: any }>()
);

export const room = createAction(
  '[Messenger::Sync] Room',
  props<RoomRequest>()
);

export const roomSuccess = createAction(
  '[Messenger::Sync] Room Success',
  props<{
    roomList: RoomInfo[];
    roomUserInfoMap: {
      [param: string]: {
        userInfoShortList: UserInfoShort[];
        userInfoList: RoomUserInfo[];
      };
    };
    syncDate: string;
  }>()
);

export const roomFailure = createAction(
  '[Messenger::Sync] Room Failure',
  props<{ error: any }>()
);

export const updateRoomForNewEventMessage = createAction(
  '[Messenger::Sync] updateRoomForNewEventMessage',
  props<{
    roomSeq: string;
    info: Info<EventJson>;
  }>()
);

export const refreshRoom = createAction(
  '[Messenger::Sync] refresh room in sync',
  props<InfoRequest>()
);
export const refreshRoomSuccess = createAction(
  '[Messenger::Sync] refresh room in sync Success',
  props<{
    roomInfo: RoomInfo;
    userInfoShortList: UserInfoShort[];
    userInfoList: RoomUserInfo[];
  }>()
);
export const refreshRoomFailure = createAction(
  '[Messenger::Sync] refresh room in sync Failure',
  props<{ error: any }>()
);

export const updateUnreadCount = createAction(
  '[Messenger::Sync] Update unread count',
  props<{
    roomSeq: string;
    noReadCnt?: number;
  }>()
);

/** 새그룹 추가 & 그룹원 추가 */
export const createGroupAndBuddy = createAction(
  '[Messenger::Sync] Group & Buddy Create',
  props<{
    groupName: string;
    trgtUserSeq: number[];
  }>()
);
export const createGroupAndBuddySuccess = createAction(
  '[Messenger::Sync] Group & Buddy Create Success',
  props<GroupAddResponse>()
);
export const createGroupAndBuddyFailure = createAction(
  '[Messenger::Sync] Group & Buddy Create Failure',
  props<{ error: any }>()
);
/** 그룹원 수정 */
export const updateGroupMember = createAction(
  '[Messenger::Sync] Update Group Member',
  props<{
    oldGroup: GroupDetailData;
    trgtUserSeq: number[];
  }>()
);
export const updateGroupMemberSuccess = createAction(
  '[Messenger::Sync] Update Group Member Success',
  props<GroupAddResponse>()
);
export const updateGroupMemberFailure = createAction(
  '[Messenger::Sync] Update Group Member Failure',
  props<{ error: any }>()
);
/** 그룹원 이동 */
export const moveGroupMember = createAction(
  '[Messenger::Sync] Move Group Member',
  props<{
    fromGroup: GroupDetailData;
    toGroup: GroupDetailData;
    trgtUserSeq: number[];
  }>()
);
export const moveGroupToFailure = createAction(
  '[Messenger::Sync] Move Group Member / To',
  props<{ error: any }>()
);
export const moveGroupFromFailure = createAction(
  '[Messenger::Sync] Move Group Member / From',
  props<{ error: any }>()
);

/** 동료 추가 */
export const addBuddy = createAction(
  '[Messenger::Sync] Buddy Add',
  props<BuddyAddRequest>()
);
export const addBuddySuccess = createAction(
  '[Messenger::Sync] Buddy Add Success',
  props<BuddyAddResponse>()
);
export const addBuddyFailure = createAction(
  '[Messenger::Sync] Buddy Add Failure',
  props<{ error: any }>()
);
/** 동료 삭제 */
export const delBuddy = createAction(
  '[Messenger::Sync] Buddy Del',
  props<BuddyDelRequest>()
);
export const delBuddySuccess = createAction(
  '[Messenger::Sync] Buddy Del Success',
  props<BuddyDelResponse>()
);
export const delBuddyFailure = createAction(
  '[Messenger::Sync] Buddy Del Failure',
  props<{ error: any }>()
);
/** 동료 삭제 및 그룹 클리어.(in profile) */
export const delBuddyAndClear = createAction(
  '[Messenger::Sync] Buddy Del and Group Clear',
  props<{ seq: number }>()
);
export const delBuddyAndClearSuccess = createAction(
  '[Messenger::Sync] Buddy Del and Group Clear Success',
  props<BuddyDelResponse>()
);
export const delBuddyAndClearFailure = createAction(
  '[Messenger::Sync] Buddy Del and Group Clear Failure',
  props<{ error: any }>()
);
/** 동료 변경(즐겨찾기) */
export const updateBuddy = createAction(
  '[Messenger::Sync] Buddy Update',
  props<BuddyUpdateRequest>()
);
export const updateBuddySuccess = createAction(
  '[Messenger::Sync] Buddy Update Success',
  props<BuddyUpdateResponse>()
);
export const updateBuddyFailure = createAction(
  '[Messenger::Sync] Buddy Update Failure',
  props<{ error: any }>()
);

/** 새그룹 추가 */
export const createGroup = createAction(
  '[Messenger::Sync] Group Create',
  props<{
    groupName: string;
  }>()
);
export const createGroupSuccess = createAction(
  '[Messenger::Sync] Group Create Success',
  props<GroupAddResponse>()
);
export const createGroupFailure = createAction(
  '[Messenger::Sync] Group Create Failure',
  props<{ error: any }>()
);
/** 그룹 업데이트 */
export const updateGroup = createAction(
  '[Messenger::Sync] Group Update',
  props<GroupUpdateRequest>()
);
export const updateGroupSuccess = createAction(
  '[Messenger::Sync] Group Update Success',
  props<GroupUpdateResponse>()
);
export const updateGroupFailure = createAction(
  '[Messenger::Sync] Group Update Failure',
  props<{ error: any }>()
);
/** 그룹 삭제 */
export const delGroup = createAction(
  '[Messenger::Sync] Group Del',
  props<{
    group: GroupDetailData;
  }>()
);
export const delGroupSuccess = createAction(
  '[Messenger::Sync] Group Del Success',
  props<GroupDelResponse>()
);
export const delGroupFailure = createAction(
  '[Messenger::Sync] Group Del Failure',
  props<{ error: any }>()
);

/** 방 인원 클리어 */
export const clearRoomUsers = createAction(
  '[Messenger::Sync] Clear room users.',
  props<{ roomSeq: string; userSeqs: number[] }>()
);
