DELIMITER //

CREATE PROCEDURE InitUsercomplaintSession ( 
    IN mobileNumber VARCHAR(15), 
    IN emailId VARCHAR(100), 
    IN firstName VARCHAR(50), 
    IN lastName VARCHAR(50)
)   
BEGIN
    DECLARE currentDate DATETIME;
    DECLARE endDate DATETIME;
    DECLARE sessionExists BOOLEAN DEFAULT FALSE;
    
    -- Calculate current date and end date (start date + 24 hours)
    -- We are expiring the session in 24 hours
    SET currentDate = NOW();
    SET endDate = DATE_ADD(currentDate, INTERVAL 24 HOUR);
    
    -- Insert the new session record
    INSERT INTO UserComplaintSessions (EmailId, FirstName, LastName, Mobile, ComplaintStatus, StartDate, EndDate)
        VALUES (emailId, firstName, lastName, mobileNumber, 1, currentDate, endDate);

    SET sessionExists = TRUE;
    SELECT sessionExists;
END

DELIMITER ;