import { Action } from '@ngrx/store';

import { RPCClientError } from '@loafer/ng-rpc/protocol';

import { Member } from '@overflow/commons-typescript/model/member';
import { PageParams, Page } from 'app/commons/model';

export enum ActionType {
  ReadAllByMember = '[Notification.notification] ReadAllByMember',
  ReadAllByMemberSuccess = '[Notification.notification] ReadAllByMemberSuccess',
  ReadAllByMemberFailure = '[Notification.notification] ReadAllByMemberFailure',
  MarkAllAsRead = '[Notification.notification] MarkAllAsRead',
  MarkAllAsReadSuccess = '[Notification.notification] MarkAllAsReadSuccess',
  MarkAllAsReadFailure = '[Notification.notification] 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) {}
}

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) {}
}

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

  constructor(public payload: RPCClientError) {}
}


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