class Csv::Admissions::Applicants::FamilyGeneralService < Csv::Admissions::Applicants::Service
  def call
    CSV.generate do |csv|
      csv << headers
      applicants.each do |applicant|
        csv << content(applicant)
      end
    end
  end

  private
    def associations
      [:family, :status, :tags]
    end

    def headers
      [
        'Student Code',
        'Student ID',
        'Student First Name',
        'Student Last Name',
        'DOB',
        'Gender',
        'Application Grade Code',
        'Application Grade Label',
        'Application Name',
        'Status',
        'Created Date',
        'Submitted Date',
        'Applicant Tags',
        'Family Tags',
        'Family Code',
        'Family ID',
        'Family Name',
        'Family Mailing Address',
        'Family Mailing Address 2',
        'Family Mailing City',
        'Family Mailing State',
        'Family Mailing Zip',
        'Family Billing Address',
        'Family Billing Address 2',
        'Family Billing City',
        'Family Billing State',
        'Family Billing Zip'
      ]
    end

    def content(applicant)
      [
        applicant.student&.code,
        applicant.student&.id,
        applicant.reviewed_prop(:first_name),
        applicant.reviewed_prop(:last_name),
        applicant.reviewed_prop(:date_of_birth),
        applicant.reviewed_prop(:gender_label),
        applicant.grade,
        grade_levels[applicant.grade],
        applicant.application.name,
        applicant.system_status,
        applicant.created_date,
        applicant.submission_date,
        applicant.tags.map(&:name).join(', '),
        family_tags[applicant.family_id]&.tags&.map(&:name)&.join(', '),
        applicant.family.code,
        applicant.family.id,
        applicant.family.name,
        applicant.family.address,
        applicant.family.address_ext,
        applicant.family.city,
        applicant.family.state,
        applicant.family.zip,
        applicant.family.address_2,
        applicant.family.address_ext_2,
        applicant.family.city_2,
        applicant.family.state_2,
        applicant.family.zip_2
      ]
    end
end
