module DataHelpers
  class Project
    attr_reader :data

    def initialize(user_name:)
      @stamp = Time.stamp.slice(0..11)
      @data = base_data.merge(user_data(user_name))
    end

    def add_optional_fields
      @data.merge!(
        description: "Watir Project Description #{@stamp}"
      )
    end

    def add_new_dropdown_fields
      @data.merge!(
        artist: "Watir Artist #{@stamp}"
      )
    end

    private

    def user_data(user_name)
      yml_data = yml_file[:user_dependent_data][user_name]
      fail "no user data found for #{user_name}!" unless yml_data
      yml_data
    end

    def yml_file
      YAML.load_file File.join(Support::Paths.cucumber_root, "features", "yml", "project.yml")
    end

    def base_data
      {
        name: "Watir Project #{@stamp}",
        code: "Watir#{@stamp}",
        description: nil
      }
    end
  end
end
