module BenefitsWordDocService
    class WordDocProcessor

        def initialize(word_doc, employer=nil)
            @word_doc = word_doc
            if employer
                @employer = employer
            else
                @employer = Employer.new
                @employer.build_id_card_setup
            end
        end

        def call
            doc = Docx::Document.open(@word_doc)
            data_lines = doc.paragraphs.map { |p| p.to_s.squish }.reject!(&:empty?)

            employer_information, plans_and_network = data_lines.split("Medical Plan")
            plan_information, network_information = plans_and_network.split("Claims Submission")

            # employer_information = data_lines.slice(0, start_of_plans_index)
            # plan_information = data_lines.slice(start_of_plans_index + 1..)
            # network_information = data_lines.slice(start_of_network_index + 1..)

            @employer = BenefitsWordDocService::MapEmployerInformation.new(@employer, employer_information).call
            @employer = BenefitsWordDocService::MapEmployerLogo.new(@employer, @word_doc).call
            @employer = BenefitsWordDocService::MapPlansInformation.new(@employer, plan_information).call
            @employer = BenefitsWordDocService::MapNetworkInformation.new(@employer, network_information).call

            @employer

        end
        
    end
end