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

      def to_xls
        DiscoveryMusicCueSheet.build(workbook, report_data, report_header_data)
        package.to_stream.read
      end

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

      private

      attr_reader :video

      def report_header_data
        DiscoveryMusicCueHeaderData.new(video)
      end

      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
