You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: case_contact_populator.rb
    path of file: ./repos/casa/lib/tasks/data_post_processors
    
    the code of the file until where you have to start completion: module CaseContactPopulator
  def self.populate
    CaseContact.find_each do |case_contact|
      # Get rid of drafts
      unless case_contact.casa_case
        case_contact.destroy
      end
      casa_org = case_contact.casa_case.casa_org
      case_contact.contact_types&.each do |contact_type|
        ct_name = contact_type.name
        cts_by_name = ContactType.where(name: ct_name)
        ct = cts_by_name.find { |ct| ct.contact_type_group.casa_org == casa_org }
        unless ct
          if cts_by_name.any?
            ctg_name = cts_by_name.fi
    
  def self.populate
    CaseContact.find_each do |case_contact|
      # Get rid of drafts
      unless case_contact.casa_case
        case_contact.destroy
      end
      casa_org = case_contact.casa_case.casa_org
      case_contact.contact_types&.each do |contact_type|
        ct_name = contact_type.name
        cts_by_name = ContactType.where(name: ct_name)
        ct = cts_by_name.find { |ct| ct.contact_type_group.casa_org == casa_org }
        unless ct
          if cts_by_name.any?
            ctg_name = cts_by_name.first.contact_type_group.name
            org_ctg = ContactTypeGroup.find_by(casa_org: casa_org, name: ctg_name)
            if org_ctg
              ContactType.find_or_create_by!(contact_type_group: org_ctg, name: ct_name)
            else
              ContactTypeGroup.find_or_create_by!(casa_org: casa_org, name: ctg_name)
            end
          else
            new_ctg = ContactTypeGroup.find_or_create_by!(casa_org: casa_org, name: "#{ctg_name} Group")
            ContactType.find_or_create_by!(contact_type_group: new_ctg, name: ct_name)
          end