| package framework |
|
|
| import ( |
| "errors" |
| "fmt" |
|
|
| "project/internal/domain" |
| ) |
|
|
| func ValidateFramework(fw *domain.InterviewFramework) error { |
| if fw == nil { |
| return errors.New("framework is nil") |
| } |
|
|
| if fw.Framework.ID == "" { |
| return errors.New("framework.id is required") |
| } |
|
|
| if fw.Framework.Name == "" { |
| return errors.New("framework.name is required") |
| } |
|
|
| if len(fw.Interview.Sections) == 0 { |
| return errors.New("interview.sections must not be empty") |
| } |
|
|
| sectionIDs := map[string]bool{} |
| questionIDs := map[string]bool{} |
|
|
| for _, sec := range fw.Interview.Sections { |
| if sec.ID == "" { |
| return errors.New("section.id is required") |
| } |
| if sectionIDs[sec.ID] { |
| return fmt.Errorf("duplicate section.id: %s", sec.ID) |
| } |
| sectionIDs[sec.ID] = true |
|
|
| if len(sec.Questions) == 0 { |
| return fmt.Errorf("section %s must have at least one question", sec.ID) |
| } |
|
|
| for _, q := range sec.Questions { |
| if q.ID == "" { |
| return fmt.Errorf("question.id required in section %s", sec.ID) |
| } |
| if questionIDs[q.ID] { |
| return fmt.Errorf("duplicate question.id: %s", q.ID) |
| } |
| questionIDs[q.ID] = true |
| } |
| } |
|
|
| return nil |
| } |
|
|