# frozen_string_literal: true

# This file is part of RASN1
# See https://codeberg.org/lemontree55/rasn1 for more informations
# Copyright (C) 2016-2024 Sylvain Daubert <sylvain.daubert@laposte.net>
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
# This program is published under MIT license.

module RASN1
  # Base error class
  class Error < StandardError; end

  # ASN.1 encoding/decoding error
  class ASN1Error < Error; end

  # ASN.1 class error
  class ClassError < Error
    # @return [String]
    def message
      "Tag class should be a symbol among: #{Types::Base::CLASSES.keys.join(', ')}"
    end
  end

  # Enumerated error
  class EnumeratedError < Error; end

  # CHOICE error: {Types::Choice#chosen} not set
  class ChoiceError < RASN1::Error
    # @param object [Types::Base]
    def initialize(object)
      @object = object
      super()
    end

    # @return [String]
    def message
      "CHOICE #{@object.name}: #chosen not set"
    end
  end

  # Exception raised when a constraint is not verified on a constrained type.
  # @version 0.11.0
  # @author Sylvain Daubert
  class ConstraintError < Error
    # @param object [Types::Base]
    def initialize(object)
      @object = object
      super()
    end

    # @return [String]
    def message
      "Constraint not verified on #{@object.inspect}"
    end
  end

  # Exception raised when model validation fails
  # @since 0.12.0
  class ModelValidationError < Error
  end
end
