module IdCardPrinterService
    class SampleCardsGenerator

        def initialize(employer_id)
            @employer_id = employer_id
            @employer = Employer.includes(id_card_setup: [:provider_section, :rx_section]).find(@employer_id)
            @card_setup = @employer.id_card_setup
        end

        def call
            IdCard::PrintData.where(employer_id: @employer.id).destroy_all
            IdCardPrinterService::SampleDataFormatter.new(@employer).call

            batch = IdCard::PrintData.where(employer_id: @employer.id).where.not(plan_id: nil)
            jasper_batch_id = "#{@employer.name.delete(" ")}Samples-#{Time.current.utc.to_i}"
            batch.update!(jasper_batch_id: jasper_batch_id)
            batch_pdf = IdCardPrinterService::PdfBatchProcessor.new(@card_setup.card_template, jasper_batch_id, "SampleCard").call

            batch_pdf
        end
    end
end
