class Admins::ImportHackExcel < BaseImportXlsx
  Data = Struct.new(:task_name, :desc, :difficulty, :time, :language, :code, :login, :set_input1, :set_output1, :set_input2, :set_output2, :set_input3, :set_output3, :set_input4, :set_output4)

  def read_each(&block)
    sheet.each_row_streaming(pad_cells: true, offset: 1) do |row|
      data = row.map(&method(:cell_value))[0..14]
      block.call Data.new(*data)
    end
  end

  private

  def check_sheet_valid!
    raise_import_error('请按照模板格式导入') if sheet.cell(1, 7).to_s.strip != "用户名"
  end

  def cell_value(obj)
    obj&.cell_value&.to_s&.strip
  end
end
