import { User, Address } from '../../models/user.model';
import { CustomerSearch } from '../../models/customer-search.model';
import { CustomerSearchResponse } from '../../models/customer-search-response.model';

export const SEARCH_USER = '[CUSTOMER] Search for customer';
export const SET_ACTIVE_USER = '[CUSTOMER] Set active customer in tab';
export const ADD_USER = '[CUSTOMER] Add new customer to store';
export const SET_EDIT_USER = '[CUSTOMER] Customer which data will be updated';
export const SET_EDIT_USER_ID = '[CUSTOMER] Customer which data will be updated by id';
export const DELETE_CUSTOMER_FOR_PROCESS = '[CUSTOMER] Delete customer for process';
export const CURRENT_CUSTOMER_PAGE_LOADED = '[CUSTOMER] Load current customer page';
export const ADD_CUSTOMERS = '[CUSTOMER] Add customers to store';
export const SET_DEFAULT_SHIPPING_ADDRESS = '[CUSTOMER] Set default shipping address';
export const ADD_NEW_SHIPPING_ADDRESS = '[CUSTOMER] Add new delivery address';
export const SET_DEFAULT_INVOICE_ADDRESS = '[CUSTOMER] Set default invoice address';
export const ADD_NEW_INVOICE_ADDRESS = '[CUSTOMER] Add new invoice address';
export const RELOAD_STATE = '[CUSTOMER] Reload data from API';
export const SET_LAST_CREATED_CUSTOMER_ID = '[CUSTOMER] Set last created customer id';
export const SET_CACHED_CUSTOMERS = '[CUSTOMER] Set cached customer results';
export const CLEAR_CACHED_CUSTOMERS = '[CUSTOMER] Clear cached customer results';
export const CLEAR_LAST_CUSTOMER_CREATED_ID = '[CUSTOMER] Clear last customer created id';

export class SearchUser {
  static readonly type = SEARCH_USER;

  constructor(public payload: string) {}
}

export class SetActiveUser {
  static readonly type = SET_ACTIVE_USER;

  constructor(public payload: User, public cartHasItemForDownload = false, public cartEntriesIds = []) {}
}

export class AddUser {
  static readonly type = ADD_USER;

  constructor(public payload: User, public setActiveUser: boolean) {}
}

export class SetUserDetails {
  static readonly type = SET_EDIT_USER;

  constructor(public payload: User, public addBreadcrumb: boolean = true) {}
}

export class SetUserDetailsById {
  static readonly type = SET_EDIT_USER_ID;

  constructor(public payload: number, public addBreadcrumb: boolean = true) {}
}

export class DeleteCustomerForProcess {
  static readonly type = DELETE_CUSTOMER_FOR_PROCESS;

  constructor(public payload: number) {}
}

export class CurrentCustomerPageLoaded {
  static readonly type = CURRENT_CUSTOMER_PAGE_LOADED;

  constructor(public page: number) {}
}

export class AddCustomers {
  static readonly type = ADD_CUSTOMERS;

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

export class SetDefaultShippingAddress {
  static readonly type = SET_DEFAULT_SHIPPING_ADDRESS;

  constructor(public customerId: number, public shippingAddress: Address) {}
}

export class AddNewShippingAddress {
  static readonly type = ADD_NEW_SHIPPING_ADDRESS;

  constructor(public customerId: number, public shippingAddress: Address) {}
}

export class AddNewInvoiceAddress {
  static readonly type = ADD_NEW_INVOICE_ADDRESS;

  constructor(public customerId: number, public invoiceAddress: Address) {}
}

export class SetDefaultInvoiceAddress {
  static readonly type = SET_DEFAULT_INVOICE_ADDRESS;

  constructor(public customerId: number, public invoiceAddress: Address) {}
}

export class ReloadCustomersData {
  static readonly type = RELOAD_STATE;

  constructor(
    public customers: { [id: number]: User },
    public lastCreatedCustomerId: number,
    public cachedCustomerSearch: { [id: number]: CustomerSearchResponse }
  ) {}
}

export class SetLastCreatedCustomerId {
  static readonly type = SET_LAST_CREATED_CUSTOMER_ID;

  constructor(public customerId?: number) {}
}

export class SetCachedCustomers {
  static readonly type = SET_CACHED_CUSTOMERS;

  constructor(public cachedCustomerSearch: CustomerSearchResponse) {}
}

export class ClearCachedCustomers {
  static readonly type = CLEAR_CACHED_CUSTOMERS;
}

export class ClearLastCustomerCreatedId {
  static readonly type = CLEAR_LAST_CUSTOMER_CREATED_ID;
}
