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

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

import { Target } from '../../model';
import { Domain } from '../../../domain/model';

export enum ActionType {
  ReadAllByDomain = '[Target.ReadAllByDomain] ReadAllByDomain',
  ReadAllByDomainSuccess = '[Target.ReadAllByDomainSuccess] ReadAllByDomainSuccess',
  ReadAllByDomainFailure = '[Target.ReadAllByDomainFailure] ReadAllByDomainFailure',
}

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

  constructor(public payload: Domain) {}
}

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

  constructor(public payload: Target[]) {}
}

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

  constructor(public payload: RPCClientError) {}
}

export type Actions =
  | ReadAllByDomain
  | ReadAllByDomainSuccess
  | ReadAllByDomainFailure
;
