% WRITTEN BY CAGDAS

classdef Controller < handle
    %CONTROLLER Summary of this class goes here
    %   Detailed explanation goes here
    
    properties (SetAccess = private)
        currentSleepPattern % hold current Sleep Pattern shown in screen
        currentSuggestions % hold current Sleep suggestion shown in screen
        currentHeartRate % hold current Heart rate shown in screen
        currentUser % % hold loginned user
        
    end
    properties
        motoActvManager % references to motoactvmanager
        accountManager  %references to accountmanager
        downloadEnabled = 0 % this is for demo purpose only, not shown in 
        %class diagrams
    end
    
    methods
        function CTRL = Controller(varargin)
            if(nargin >0) CTRL.downloadEnabled = varargin{1}; % if demo option enabled
            msgbox('Download Functionality enabled');
            end
            %initilization 
            CTRL.motoActvManager = MotoActvManager(CTRL);
            CTRL.accountManager = AccountManager();
            %show login screen
            GUI_showLoginScreen(CTRL);
        end
        %gets currentHeartRate
        function hr = getHeartRateData(CTRL)
            hr = CTRL.currentHeartRate;
        end
        %sets currentHeartRate
        function res = saveHeartRateData(CTRL,data)
            CTRL.currentHeartRate = data;
            res =true;
        end
        %gets currentSleepPattern
        function hr = getSleepPatterns(CTRL)
            hr = CTRL.currentSleepPattern;
        end
        %sets currentSleepPattern
        function res = saveSleepPatterns(CTRL,data)
            CTRL.currentSleepPattern = data;
            res =true;
        end
        %gets currentSuggestion
        function hr = getSuggestion(CTRL)
            hr = CTRL.currentSuggestions;
        end
        %sets currentSuggestion
        function res = saveSuggestions(CTRL,data)
            CTRL.currentSuggestions = data;
            res =true;
        end
        %only login sets currentUser
        function login(CTRL, userName, password )
        %CONTROLLER_LOGIN Summary of this function goes here
        %   Detailed explanation goes here
            user.name = userName;
            user.password = password;

            user = CTRL.accountManager.verifyUser(user);
            if(user.id == -1)
                msgbox('Incorrect user name');
            elseif(user.id == 0)
                msgbox('Incorrect password');
            else
                %
                CTRL.currentUser = user;
                close all;
                GUI_showMainScreen(CTRL);
            end
    
        end
        %gets currentUser
        function user = getUser(CTRL)
            user = CTRL.currentUser;

        end
        %enables a highlevel user to actas another person
        %this function is only called from account manager
        %which is only open to highlevel users
        function actAs(CTRL,username)
                user = DatabaseManager.getUserFromName(username);
                CTRL.currentUser.name = user.name;
                CTRL.currentUser.id = user.id;
                %since we are not changing currentUSertype
                %user will be able to get back to accountmanagement screen
                %and change back to his original user
        end
                
    end
    
end

