import { ApplicationError, IErrorDetail } from '@somma/node-errors';

export class IntegrationInternalError extends ApplicationError {
  public resolved = false;

  constructor(message?: string, details?: IErrorDetail, causedBy?: any) {
    super(500, 'INTERNAL_ERROR', message ?? 'Integration internal error', details, causedBy);
  }
}

export class AccountingSegmentNotFound extends ApplicationError {
  public resolved = false;

  constructor(message?: string, details?: IErrorDetail, causedBy?: any) {
    super(404, 'ACCOUNTING_SEGMENT_NOT_FOUND', message ?? 'Accounting segment not found', details, causedBy);
  }
}

export class SupplierNotFound extends ApplicationError {
  public resolved = false;

  constructor(message?: string, details?: IErrorDetail, causedBy?: any) {
    super(502, 'ERP_SUPPLIER_NOT_FOUND', message ?? 'Supplier not found', details, causedBy);
  }
}

export class BusinessUnitNotFound extends ApplicationError {
  public resolved = false;

  constructor(message?: string, details?: IErrorDetail, causedBy?: any) {
    super(502, 'ERP_BUSINESS_UNIT_NOT_FOUND', message ?? 'Business Unit not found', details, causedBy);
  }
}

export class CFOPNotFound extends ApplicationError {
  public resolved = false;

  constructor(message?: string, details?: IErrorDetail, causedBy?: any) {
    super(502, 'ERP_CFOP_TRANSACTION_NOT_FOUND', message ?? 'CFOP not found', details, causedBy);
  }
}

export class ERPIntegrationError extends ApplicationError {
  public resolved = false;

  constructor(message?: string, details?: IErrorDetail, causedBy?: any) {
    super(502, 'ERP_INTEGRATION_ERROR', message ?? 'ERP Integration error', details, causedBy);
  }
}

export class CannotUpdateInvoiceStatus extends ApplicationError {
  public resolved = false;

  constructor(message?: string, details?: IErrorDetail, causedBy?: any) {
    super(502, 'CANNOT_UPDATE_INVOICE_STATUS', message ?? 'Invoice integrated but Cannot update status on 01CM', details, causedBy);
  }
}

export class CannotUpdateDebitsStatus extends ApplicationError {
  public resolved = false;

  constructor(message?: string, details?: IErrorDetail, causedBy?: any) {
    super(500, 'CANNOT_UPDATE_DEBITS_STATUS', message ?? 'Cannot update debit status after invoice integration', details, causedBy);
  }
}
