import { ItemDTO, ListResponseArgsOfItemDTO } from '@swagger/cat';
import { Search } from '../../models/search.model';

export const LOAD_RECENT_PRODUCTS = '[PRODUCTS] Load recent';
export const GET_PRODUCTS = '[PRODUCTS] Get';
export const SET_PRODUCTS = '[PRODUCTS] Set';
export const SET_PRODUCT_IF_IT_DOES_NOT_EXIST = '[PRODUCTS] Set product if it does not exist';
export const ADD_SELECTED_PRODUCT = '[PRODUCTS] Add selected';
export const DELETE_PRODUCTS_FOR_PROCESS = '[PRODUCTS] Delete products for process';
export const RELOAD_STATE = '[PRODUCTS] Reload data from API';
export const SET_CACHED_RESULTS = '[PRODUCTS] Set Cached results';
export const CLEAR_CACHED_RESULTS = '[PRODUCTS] Set Cached results';

export class LoadRecentProducts {
  static readonly type = LOAD_RECENT_PRODUCTS;

  constructor() {}
}

export class GetProducts {
  static readonly type = GET_PRODUCTS;

  constructor(public payload: Search) {}
}

export class SetProducts {
  static readonly type = SET_PRODUCTS;
  // TODO: remove optional from processId
  constructor(public payload: ItemDTO[], public search: Search, public processId?: number, public setBreadcrumb = false) {}
}

export class SetProductIfItDoesNotExist {
  static readonly type = SET_PRODUCT_IF_IT_DOES_NOT_EXIST;

  constructor(public payload: ItemDTO) {}
}

export class AddSelectedProduct {
  static readonly type = ADD_SELECTED_PRODUCT;

  constructor(public payload: ItemDTO, public index: number) {}
}

export class DeleteProductsForProcess {
  static readonly type = DELETE_PRODUCTS_FOR_PROCESS;

  constructor(public payload: number) {}
}

export class SetProductCachedResults {
  static readonly type = SET_CACHED_RESULTS;

  constructor(public cachedResults: ListResponseArgsOfItemDTO) {}
}

export class ClearProductCachedResults {
  static readonly type = CLEAR_CACHED_RESULTS;
}

export class ReloadProductsData {
  static readonly type = RELOAD_STATE;

  constructor(
    public products: { [key: number]: { [key: number]: ItemDTO } },
    public cachedProductResults: { [id: number]: { result: ListResponseArgsOfItemDTO } }
  ) {}
}
