@startuml Meeting Creation Sequence Diagram
title Meeting Creation Process

actor User
participant "MeetingSet" as MS
participant "Utils" as U
participant "Meeting\n(WebinarMeeting/\nGroupMeetMeeting/\nMeetupMeeting)" as M
participant "Resource\n(Person/Room)" as R

User -> MS: addMeeting()
activate MS

note right: Select Meeting Type
MS -> User: Display meeting type menu\n(1. webinar, 2. group meet, 3. meetup)
User -> U: Select meeting type
U -> MS: Return type (1-3)

alt Invalid type selected
    MS -> User: "invalid option, try again"
    MS -> User: Re-display type menu
end

note right: Input Start Time
MS -> User: "start date and time:"
User -> MS: inputDateAndTime()
MS -> U: Read date/time input
U -> MS: Return start Calendar

note right: Input End Time
loop End time validation
    MS -> User: "end date and time:"
    User -> MS: inputDateAndTime()
    MS -> U: Read date/time input
    U -> MS: Return end Calendar
    
    alt End time not after start time
        MS -> User: "end time need to be after start time"
    end
end

note right: Resource Selection
loop Resource selection and validation
    MS -> User: "choose resources:"
    MS -> MS: showEditMeetingResourcesMenu(resources)
    
    loop Resource menu operations
        MS -> User: Display resource menu\n(1. add person, 2. add room, 3. display, 4. done)
        User -> U: Select option
        U -> MS: Return choice
        
        alt Add Person
            MS -> User: Request person ID
            User -> U: Enter person ID
            U -> MS: Return person ID
            MS -> R: Find person by ID
            R -> MS: Return Person resource
            MS -> MS: Add person to resources set
            
        else Add Room
            MS -> User: Request room number
            User -> U: Enter room number
            U -> MS: Return room number
            MS -> R: Find room by number
            R -> MS: Return Room resource
            MS -> MS: Add room to resources set
            
        else Display Resources
            MS -> User: Display current resources
            
        else Done
            break
        end
    end
    
    note right: Create Meeting Object
    alt Meeting Type = Webinar
        MS -> M: new WebinarMeeting(id, resources, start, end)
    else Meeting Type = Group Meet
        MS -> M: new GroupMeetMeeting(id, resources, start, end)
    else Meeting Type = Meetup  
        MS -> M: new MeetupMeeting(id, resources, start, end)
    end
    
    M -> M: checkResources(resources)
    
    alt Resource validation fails
        M -> MS: throw IllegalArgumentException
        MS -> User: Display error message\n"try again"
        note right: Loop continues for resource re-selection
    else Resource validation succeeds
        M -> MS: Return meeting object
        break
    end
end

note right: Add Meeting to System
MS -> MS: set.add(meeting)

note right: Check for Resource Conflicts
MS -> MS: willClash(meeting)

loop Check against existing meetings
    MS -> MS: Check time overlap with existing meetings
    alt Time overlaps
        MS -> MS: Check resource conflicts
        alt Resource conflict found
            MS -> User: Display conflicting resource info
        end
    end
end

alt Meeting has conflicts
    MS -> User: "Clashing resources, please make required changes"
    MS -> MS: editMeeting(meeting)
    note right: User can modify meeting to resolve conflicts
else No conflicts
    MS -> User: Meeting created successfully
end

deactivate MS

@enduml