import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import { Sensor } from '@overflow/commons-typescript/model/sensor';
import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams';
import { Page } from '@overflow/commons-typescript/model/commons/Page';

export enum ActionType {
  ReadAllByDomainID = '[Sensor.list] ReadAllByDomainID',
  ReadAllByDomainIDSuccess = '[Sensor.list] ReadAllByDomainIDSuccess',
  ReadAllByDomainIDFailure = '[Sensor.list] ReadAllByDomainIDFailure',

  Read = '[Sensor.detail] Read',
  ReadSuccess = '[Sensor.detail] ReadSuccess',
  ReadFailure = '[Sensor.detail] ReadFailure',

  Modify = '[Sensor.detail] Modify',
  ModifySuccess = '[Sensor.detail] ModifySuccess',
  ModifyFailure = '[Sensor.detail] ModifyFailure',
}

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

  constructor(public payload: {domainID: number, pageParams: PageParams}) {}
}

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

  constructor(public payload: Page<Sensor>) {}
}

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

  constructor(public payload: RPCClientError) {}
}

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

  constructor(public payload: number) {}
}

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

  constructor(public payload: Sensor) {}
}

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

  constructor(public payload: RPCClientError) {}
}

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

  constructor(public payload: Sensor) {}
}

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

  constructor(public payload: Sensor) {}
}

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

  constructor(public payload: RPCClientError) {}
}

export type Actions =
  | ReadAllByDomainID
  | ReadAllByDomainIDSuccess
  | ReadAllByDomainIDFailure
  | Read
  | ReadSuccess
  | ReadFailure
  | Modify
  | ModifySuccess
  | ModifyFailure
;
