package com.magistr.app.utils;

import com.magistr.app.model.AcademicYear;
import com.magistr.app.model.EducationForm;
import com.magistr.app.model.Speciality;
import com.magistr.app.model.SpecialtyProfile;

import java.util.List;

public final class AcademicCalendarTitleBuilder {

    private static final String SEPARATOR = " — ";

    private AcademicCalendarTitleBuilder() {
    }

    public static String build(AcademicYear academicYear,
                               Speciality speciality,
                               SpecialtyProfile profile,
                               EducationForm studyForm) {
        List<String> parts = List.of(
                normalize(speciality == null ? null : speciality.getSpecialityCode()),
                normalize(profile == null ? null : profile.getName()),
                normalize(studyForm == null ? null : studyForm.getName()),
                normalize(academicYear == null ? null : academicYear.getTitle())
        );
        if (parts.stream().anyMatch(String::isBlank)) {
            throw new IllegalArgumentException(
                    "Невозможно сформировать название календарного графика из выбранных параметров"
            );
        }
        return String.join(SEPARATOR, parts);
    }

    private static String normalize(String value) {
        return value == null ? "" : value.trim();
    }
}
