with Library;
with Io_Exceptions;
with Io;
use Io;
package body User_Information is

    type Catagory is (C_Name, C_Phone_Number, C_Mail_Stop,
                      C_Default_Print_Queue, C_Division, C_Group);

    Info_Filename : constant String := ".User_Information";

    function Root_Library return String is separate;

    function Get_Information
                (Info : Catagory; Account_Name : String) return String is

        F : File_Type;
        Line : String (1 .. 80);
        Count : Natural;
    begin
        Open (F, In_File, Root_Library & Account_Name & Info_Filename);
        for I in Catagory'First .. Info loop
            Get_Line (F, Line, Count);
        end loop;
        Close (F);
        return (Line (1 .. Count));
    exception
        when others =>
            return "Not Initialized";
    end Get_Information;

    function Get_Name (Account_Name : String) return String is
    begin
        return Get_Information (C_Name, Account_Name);
    end Get_Name;

    function Get_Phone_Number (Account_Name : String) return String is
    begin
        return Get_Information (C_Phone_Number, Account_Name);
    end Get_Phone_Number;

    function Get_Mail_Stop (Account_Name : String) return String is
    begin
        return Get_Information (C_Mail_Stop, Account_Name);
    end Get_Mail_Stop;

    function Get_Default_Print_Queue (Account_Name : String) return String is
    begin
        return Get_Information (C_Default_Print_Queue, Account_Name);
    end Get_Default_Print_Queue;

    function Get_Division (Account_Name : String) return String is
    begin
        return Get_Information (C_Division, Account_Name);
    end Get_Division;

    function Get_Group (Account_Name : String) return String is
    begin
        return Get_Information (C_Group, Account_Name);
    end Get_Group;

    procedure Show (Account_Name : String) is
    begin
        Put_Line ("Information for " & Account_Name);
        for I in Catagory'First .. Catagory'Last loop
            Put_Line (Catagory'Image (I) & " => " &
                      Get_Information (I, Account_Name));
        end loop;
    end Show;

    procedure Set (Account_Name        : String := "";
                   Full_Name           : String := "";
                   Phone_Number        : String := "";
                   Mail_Stop           : String := "";
                   Default_Print_Queue : String := "";
                   Division            : String := "";
                   Group               : String := "") is
        F : File_Type;
    begin
        begin
            Create (F, Out_File, Root_Library & Account_Name & Info_Filename);
        exception
            when Io_Exceptions.Name_Error =>
                Library.Create_Directory (Name => Root_Library & Account_Name);
                Create (F, Out_File,
                        Root_Library & Account_Name & Info_Filename);
        end;
        for I in Catagory loop
            case I is
                when C_Name =>
                    Put_Line (F, Full_Name);
                when C_Phone_Number =>
                    Put_Line (F, Phone_Number);
                when C_Mail_Stop =>
                    Put_Line (F, Mail_Stop);
                when C_Default_Print_Queue =>
                    Put_Line (F, Default_Print_Queue);
                when C_Division =>
                    Put_Line (F, Division);
                when C_Group =>
                    Put_Line (F, Group);
            end case;
        end loop;
        Close (F);
    end Set;
end User_Information;