with Log;
with Errors;
with Profile;
with Defaults;
with Subtypes;
use Subtypes;
with Arguments;
with Assertions;
with Debug_Tools;
with Display_Defaults;
procedure Set_Defaults (Catalog : in Simple_Name := ">> CATALOG NAME <<";
                        Version : in Simple_Name := ">> VERSION IDENTIFIER <<";
                        User : in User_Name := "<CURRENT_USER>";
                        Response : in String := "<PROFILE>") is
    --
    Old_Response_Profile : Profile.Response_Profile := Profile.Get;
    New_Response_Profile : Profile.Response_Profile := Profile.Value (Response);
    --
    package Error is
       new Errors  
              (Old_Response_Profile, New_Response_Profile, "Set_Defaults");
    --
begin
    Profile.Set (New_Response_Profile);
    Log.Put_Line ("[Set_Defaults (Catalog => """ & Catalog &
                  """, Version => """ & Version & """, User => """ &
                  User & """, Response => """ & Response & """)]",
                  Profile.Auxiliary_Msg);
    declare  
        The_User : constant Simple_Name :=
           Arguments.User_From (User_Argument => User);
        The_Catalog : constant Simple_Name :=  
           Arguments.Simple_Catalog_From (This_Catalog_Argument => Catalog);
        The_Version : constant Simple_Name :=
           Arguments.Simple_Version_From (This_Catalog_Argument => Catalog,
                                          This_Version_Argument => Version);
    begin  
        Assertions.Assert_Catalog_Exists (Arguments.Catalog_From (Catalog));
        Assertions.Assert_Version_Exists
           (Arguments.Version_From (Catalog, Version));
        Log.Put_Line ("Setting defaults");
        Defaults.Set (For_User => The_User,
                      Catalog => The_Catalog,
                      Version => The_Version);
        begin
            Display_Defaults (For_User => The_User,
                              Response => "PROPAGATE," & Response);
            --
        exception
            when others =>
                Error.Report ("Display defaults failed, quitting",
                              Nested => True);
        end;
    end;
    Log.Put_Line ("[end of Set_Defaults operation--no error(s) detected]");
    Profile.Set (Old_Response_Profile);
    --
exception
    when Arguments.Invalid_Catalog =>
        Error.Report ("Specified catalog is invalid");
    when Arguments.Invalid_Version =>
        Error.Report ("Specified version is invalid");
    when Arguments.Invalid_Username =>
        Error.Report ("Specified username is invalid");
    when Assertions.No_Such_Catalog =>
        Error.Report ("Specified catalog does not exist");
    when Assertions.No_Such_Version =>
        Error.Report ("Specified version does not exist");
    when Defaults.Io_Failure =>
        Error.Report ("Problem encountered saving defaults");
    when Error.Propagate =>
        raise;  
    when Error.Quit =>
        null;
    when others =>
        Error.Report ("EXCEPTION: " & Debug_Tools.Get_Exception_Name,
                      Profile.Exception_Msg);
        --
end Set_Defaults;