module ExcelReports
  module AudioReports
    class NatGeoMusicCueSheet
      def initialize(video)
        @video = video
      end

      def to_xls
        NatGeoMusicCueSheets::MainSheet.build(workbook, report_data)
        package.to_stream.read
      end

      def filename
        "#{video.file.filename.to_s.parameterize}_music-cue-sheet.xlsx"
      end

      private

      attr_reader :video

      def report_data
        video.audio_confirmations.order(timecode_in: :asc).map do |audio_confirmation|
          AudioConfirmationData.new(audio_confirmation)
        end
      end

      def workbook
        @workbook ||= package.workbook
      end

      def package
        @package ||= Axlsx::Package.new
      end
    end
  end
end
