DROP TRIGGER IF EXISTS `update_account_trig`;
DELIMITER ;;
CREATE TRIGGER `update_account_trig`
AFTER UPDATE ON `users`
FOR EACH ROW 
BEGIN
	IF OLD.email != NEW.email THEN
    	INSERT INTO `audit_trail` (`action_type`,`user_id`,`user_type`,`action_timestamp`) VALUES (3,NEW.id,NEW.type,NOW());
	END IF;
    IF OLD.password != NEW.password THEN
    	INSERT INTO `audit_trail` (`action_type`,`user_id`,`user_type`,`action_timestamp`) VALUES (4,NEW.id,NEW.type,NOW());
	END IF;
    IF OLD.name != NEW.name THEN
    	INSERT INTO `audit_trail` (`action_type`,`user_id`,`user_type`,`action_timestamp`) VALUES (5,NEW.id,NEW.type,NOW());
	END IF;
    IF OLD.username != NEW.username THEN
    	INSERT INTO `audit_trail` (`action_type`,`user_id`,`user_type`,`action_timestamp`) VALUES (6,NEW.id,NEW.type,NOW());
	END IF;
    IF OLD.location != NEW.location THEN
    	INSERT INTO `audit_trail` (`action_type`,`user_id`,`user_type`,`action_timestamp`) VALUES (7,NEW.id,NEW.type,NOW());
	END IF;
    IF OLD.bio != NEW.bio THEN
    	INSERT INTO `audit_trail` (`action_type`,`user_id`,`user_type`,`action_timestamp`) VALUES (8,NEW.id,NEW.type,NOW());
	END IF;
	
	IF OLD.archived = false AND OLD.archived != NEW.archived THEN
			INSERT INTO `audit_trail` (`action_type`,`user_id`,`user_type`,`action_timestamp`) VALUES (12,NEW.id,NEW.type,NOW());
	END IF;

	IF OLD.archived = true AND OLD.archived != NEW.archived THEN
			INSERT INTO `audit_trail` (`action_type`,`user_id`,`user_type`,`action_timestamp`) VALUES (13,NEW.id,NEW.type,NOW());
	END IF;
END;;
DELIMITER ;
