# typed: strict
class ActiveModelDurationValue < ActiveModel::Type::Value
  extend T::Sig

  sig do
    override
      .params(value: T.untyped)
      .returns(T.nilable(ActiveSupport::Duration))
  end
  def cast(value)
    return nil if value.nil?
    value.is_a?(Numeric) ? ActiveSupport::Duration.seconds(value) : value
  end

  sig do
    override
      .params(value: T.nilable(ActiveSupport::Duration))
      .returns(T.nilable(Numeric))
  end
  def serialize(value)
    return nil if value.nil?
    value.to_i
  end
end
