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

import { RESTClientError } from '@loafer/ng-rest';

import { DomainMember } from '@overflow/commons-typescript/model/domain';

export enum ActionType {
  SigninSuccess = '[auth.auth] SigninSuccess',
  SigninFailure = '[auth.auth] SigninFailure',

  SigninCookieSuccess = '[auth.auth] SigninCookieSuccess',
  SigninCookieFailure = '[auth.auth] SigninCookieFailure',

  SignoutSuccess = '[auth.auth] SignoutSuccess',
  SignoutFailure = '[auth.auth] SignoutFailure',
}

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

  constructor(public payload: {authToken: string, domainMember: DomainMember}) {}
}

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

  constructor(public payload: RESTClientError) {}
}

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

  constructor(public payload: DomainMember) {}
}

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

  constructor(public payload: RESTClientError) {}
}

export class SignoutSuccess implements Action {
  readonly type = ActionType.SignoutSuccess;
}

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

  constructor(public payload: RESTClientError) {}
}

export type Actions =
  | SigninSuccess
  | SigninFailure
  | SigninCookieSuccess
  | SigninCookieFailure
  | SignoutSuccess
  | SignoutFailure
;
