import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import { Member } from '@overflow/commons-typescript/model/member';
import { Page, PageParams } from '@overflow/commons-typescript/core/model';
import { Notification } from '@overflow/commons-typescript/model/notification';

export enum ActionType {
  ReadAllByMember = '[Notification.list] ReadAllByMember',
  ReadAllByMemberSuccess = '[Notification.list] ReadAllByMemberSuccess',
  ReadAllByMemberFailure = '[Notification.list] ReadAllByMemberFailure',
  MarkAllAsRead = '[Notification.mark] MarkAllAsRead',
  MarkAllAsReadSuccess = '[Notification.mark] MarkAllAsReadSuccess',
  MarkAllAsReadFailure = '[Notification.mark] MarkAllAsReadFailure',
}

export class ReadAllByMember implements Action {
  readonly type = ActionType.ReadAllByMember;

  constructor(public payload: { member: Member, pageParams: PageParams }) {}
}

export class ReadAllByMemberSuccess implements Action {
  readonly type = ActionType.ReadAllByMemberSuccess;

  constructor(public payload: Page<Notification>) {}
}

export class ReadAllByMemberFailure implements Action {
  readonly type = ActionType.ReadAllByMemberFailure;

  constructor(public payload: RPCClientError) {}
}

export class MarkAllAsRead implements Action {
  readonly type = ActionType.MarkAllAsRead;

  constructor(public payload: { member: Member, pageParams: PageParams }) {}
}

export class MarkAllAsReadSuccess implements Action {
  readonly type = ActionType.MarkAllAsReadSuccess;

  constructor(public payload: Page<Notification>) {}
}

export class MarkAllAsReadFailure implements Action {
  readonly type = ActionType.MarkAllAsReadFailure;

  constructor(public payload: RPCClientError) {}
}


export type Actions =
  | ReadAllByMember
  | ReadAllByMemberSuccess
  | ReadAllByMemberFailure
  | MarkAllAsRead
  | MarkAllAsReadSuccess
  | MarkAllAsReadFailure
;
