import { ListResponseArgs } from '@isa/common/data-access';
import { QueryTokenInput } from '../schemas';
import { ReceiptListItem } from '../models';

export const ReturnSearchErrorCode = {
  PARSE_QUERY_TOKEN: 'PARSE_QUERY_TOKEN',
} as const;

export type ReturnSearchErrorCode =
  (typeof ReturnSearchErrorCode)[keyof typeof ReturnSearchErrorCode];

export class ReturnSearchError extends Error {
  constructor(
    public readonly code: ReturnSearchErrorCode,
    message?: string,
  ) {
    super(message || code);
  }
}

export class ReturnParseQueryTokenError extends ReturnSearchError {
  constructor(
    public queryToken: QueryTokenInput,
    messsage: string,
  ) {
    super(ReturnSearchErrorCode.PARSE_QUERY_TOKEN, messsage);
  }
}

export class ReturnSearchSearchError extends ReturnSearchError {
  constructor(
    messsage: string,
    public queryToken: QueryTokenInput,
    public response?: ListResponseArgs<ReceiptListItem>,
  ) {
    super(ReturnSearchErrorCode.PARSE_QUERY_TOKEN, messsage);
  }
}
