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

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

import { Domain } from '@overflow/commons-typescript/model/domain';
import { PageParams, Page } from 'app/commons/model';
import { Target } from '@overflow/commons-typescript/model/target';

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

  ReadAllByInfra = '[Sensor.ReadAllByInfra] ReadAllByInfra',
  ReadAllByInfraSuccess = '[Sensor.ReadAllByInfraSuccess] ReadAllByInfraSuccess',
  ReadAllByInfraFailure = '[Sensor.ReadAllByInfraFailure] ReadAllByInfraFailure',

  ReadAllByTarget = '[Sensor.ReadAllByTarget] ReadAllByTarget',
  ReadAllByTargetSuccess = '[Sensor.ReadAllByTargetSuccess] ReadAllByTargetSuccess',
  ReadAllByTargetFailure = '[Sensor.ReadAllByTargetFailure] ReadAllByTargetFailure',
}

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

  constructor(public payload: { domain: Domain, pageParams: PageParams}) {}
}

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

  constructor(public payload: Page) {}
}

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

  constructor(public payload: RPCClientError) {}
}

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

  constructor(public payload: { id: string, pageParams: PageParams}) {}
}

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

  constructor(public payload: Page) {}
}

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

  constructor(public payload: RPCClientError) {}
}
//
export class ReadAllByTarget implements Action {
  readonly type = ActionType.ReadAllByTarget;

  constructor(public payload: { target: Target, pageParams: PageParams}) {}
}

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

  constructor(public payload: Page) {}
}

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

  constructor(public payload: RPCClientError) {}
}
export type Actions =
  | ReadAllByDomain
  | ReadAllByDomainSuccess
  | ReadAllByDomainFailure
  | ReadAllByInfra
  | ReadAllByInfraSuccess
  | ReadAllByInfraFailure
  | ReadAllByTarget
  | ReadAllByTargetSuccess
  | ReadAllByTargetFailure
;
