import { Action } from '@ngrx/store';
import { RESTClientError } from '@loafer/ng-rest';
import { Member } from '@overflow/commons-typescript/model/member';

export enum ActionType {
  Signin = '[member.member] Signin',
  Signout = '[member.member] Signout',

  Signup = '[member.member] Signup',
  SignupSuccess = '[member.member] SignupSuccess',
  SignupFailure = '[member.member] SignupFailure',

  Modify = '[member.member] Modify',
  ModifySuccess = '[member.member] ModifySuccess',
  ModifyFailure = '[member.member] ModifyFailure',

  ResetPassword = '[member.member] ResetPassword',
  ResetPasswordSuccess = '[member.member] ResetPasswordSuccess',
  ResetPasswordFailure = '[member.member] ResetPasswordFailure',

  ModifyPassword = '[member.member] ModifyPassword',
  ModifyPasswordSuccess = '[member.member] ModifyPasswordSuccess',
  ModifyPasswordFailure = '[member.member] ModifyPasswordFailure',
}

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

  constructor(public payload: { email: string, password: string, returnURL: string }) { }
}

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

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

  constructor(public payload: { member: Member, password: string }) { }
}

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

  constructor(public payload: Member) { }
}

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

  constructor(public payload: RESTClientError) { }
}

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

  constructor(public payload: Member ) {}
}

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

  constructor(public payload: Member) {}
}

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

  constructor(public payload: RESTClientError) {}
}

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

  constructor(public payload: string ) {}
}

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

  constructor(public payload: Member) {}
}

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

  constructor(public payload: RESTClientError) {}
}

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

  constructor(public payload: { token: string, password: string, confirmPassword: string } ) {}
}

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

  constructor(public payload: Member) {}
}

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

  constructor(public payload: RESTClientError) {}
}

export type Actions =
  | Signin
  | Signout
  | Signup
  | SignupSuccess
  | SignupFailure
  | Modify
  | ModifySuccess
  | ModifyFailure
  | ResetPassword
  | ResetPasswordSuccess
  | ResetPasswordFailure
  | ModifyPassword
  | ModifyPasswordSuccess
  | ModifyPasswordFailure
  ;
