class EdFi::Identity < ApplicationRecord
  attr_accessor :state_id

  enum status: { pending: 0, approved: 1, denied: 2, cancelled: 3 }

  belongs_to :school_year
  belongs_to :associated, polymorphic: true

  after_save :create_state_id, if: :approved?

  private
    def create_state_id
      # TODO: state_number is used by Student and state_id is used by Employee
      #       this should be refactored to use the same name
      return if associated.state_number || state_id.nil?

      associated.create_state_number(number: state_id)
    end
end
