module Interactors
  module Facts
    class Create
      include Pavlov::Interactor

      arguments :displaystring, :url, :title

      def execute
        site = query :'sites/for_url', @url

        if site.nil?
          site = command :'sites/create', @url
        end

        command :'facts/create', @displaystring, @title, @options[:current_user], site
      end

      def authorized?
        @options[:current_user]
      end

      def validate
        validate_string :title, @title
        validate_string :url, @url
        validate_nonempty_string :displaystring, @displaystring
      end
    end
  end
end

module Interactors
  module Facts
    class Create
      include Pavlov::Interactor

      arguments :displaystring, :url, :title

      def execute
        site = query :'sites/for_url', @url

        if site.nil?
          site = command :'sites/create', @url
        end

        fact = command :'facts/create', @displaystring, @title, @options[:current_user], site
        command :"facts/add_to_recently_viewed", fact.id.to_i, @options[:current_user].id.to_s
        fact
      end

      def authorized?
        @options[:current_user]
      end

      def validate
        validate_string :title, @title
        validate_string :url, @url
        validate_nonempty_string :displaystring, @displaystring
      end
    end
  end
end

Add a coll to the recently viewed factlink list.
Add a coll to the recently viewed factlink list.
