with Pathnames;
with Directory_Tools;
package body Assertions is

    procedure Assert_Empty (This_Iterator : in out
                               Directory_Tools.Object.Iterator) is
    begin
        Directory_Tools.Object.Reset (This_Iterator);
        if (not Directory_Tools.Object.Done (This_Iterator)) then
            raise Object_Already_Exists;
        end if;
    end Assert_Empty;

    procedure Assert_Not_Empty (This_Iterator : in out
                                   Directory_Tools.Object.Iterator) is
    begin
        Directory_Tools.Object.Reset (This_Iterator);
        if (Directory_Tools.Object.Done (This_Iterator)) then
            raise No_Such_Object;
        end if;
    end Assert_Not_Empty;

    procedure Assert_Not_Ambiguous (This_Iterator : in out
                                       Directory_Tools.Object.Iterator) is
        --
        Count : Natural := 0;
        --
    begin  
        Directory_Tools.Object.Reset (This_Iterator);
        while (not Directory_Tools.Object.Done (This_Iterator)) loop
            Count := Count + 1;
            if (Count > 1) then  
                raise Ambiguous_Name;
            end if;
            Directory_Tools.Object.Next (This_Iterator);
        end loop;
        Directory_Tools.Object.Reset (This_Iterator);
    end Assert_Not_Ambiguous;

    -- *****

    procedure Assert_Object_Exists (This_Object : in Full_Name) is
        --
        The_Object : Directory_Tools.Object.Iterator :=
           Directory_Tools.Naming.Resolution (This_Object);
        --
    begin  
        Assert_Not_Ambiguous (The_Object);
        Assert_Not_Empty (The_Object);
    end Assert_Object_Exists;

    procedure Assert_Catalog_Exists (This_Catalog : in Full_Name) is
    begin  
        Assert_Object_Exists (This_Catalog);
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise No_Such_Catalog;
            --
    end Assert_Catalog_Exists;

    procedure Assert_Version_Exists (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists (This_Version);
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise No_Such_Version;
            --
    end Assert_Version_Exists;

    procedure Assert_Section_Exists (This_Section : in Full_Name) is
    begin  
        Assert_Object_Exists (This_Section);
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise No_Such_Section;
            --
    end Assert_Section_Exists;

    procedure Assert_Item_Exists (This_Item : in Full_Name) is
    begin
        Assert_Object_Exists (This_Item);
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise No_Such_Item;
            --
    end Assert_Item_Exists;

    procedure Assert_Has_Sections_Context (This_Catalog : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Sections_Context_For (This_Catalog));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Sections_Context;
            --
    end Assert_Has_Sections_Context;

    procedure Assert_Has_Versions_Context (This_Catalog : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Versions_Context_For (This_Catalog));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Versions_Context;
            --
    end Assert_Has_Versions_Context;

    procedure Assert_Has_Document_Setup_File (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Document_Setup_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Document_Setup_File;
            --
    end Assert_Has_Document_Setup_File;

    procedure Assert_Has_Printer_Options_File (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists
           (Pathnames.Printer_Options_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Printer_Options_File;
            --
    end Assert_Has_Printer_Options_File;

    procedure Assert_Has_Data_File (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Data_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Data_File;
            --
    end Assert_Has_Data_File;

    procedure Assert_Has_Browser_Data_File (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Browser_Data_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Browser_Data_File;
            --
    end Assert_Has_Browser_Data_File;

    procedure Assert_Has_Release_Notice (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Release_Notice_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Release_Notice;
            --
    end Assert_Has_Release_Notice;

    procedure Assert_Has_Formatted_Release_Notice
                 (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists
           (Pathnames.Formatted_Release_Notice_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Formatted_Release_Notice;
            --
    end Assert_Has_Formatted_Release_Notice;

    procedure Assert_Has_Booklet (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Booklet_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Booklet;
            --
    end Assert_Has_Booklet;

    procedure Assert_Has_Formatted_Booklet (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Formatted_Booklet_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Formatted_Booklet;
            --
    end Assert_Has_Formatted_Booklet;

    procedure Assert_Has_Browser_View_Name_File (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists
           (Pathnames.Browser_View_Name_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Browser_View_Name_File;
            --
    end Assert_Has_Browser_View_Name_File;

    procedure Assert_Has_Browser (This_Version : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Load_Proc_Name_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Browser;
            --
    end Assert_Has_Browser;

    procedure Assert_Has_Tape_Contents (This_Version : in Full_Name) is
    begin
        Assert_Has_Browser_Data_File (This_Version);
        Assert_Has_Browser (This_Version);
        Assert_Has_Archive_Data (This_Version);
        Assert_Has_Archive_Index (This_Version);
    end Assert_Has_Tape_Contents;

    procedure Assert_Has_Archive_Data (This_Library : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Archive_Data_For (This_Library));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Archive_Data;
            --
    end Assert_Has_Archive_Data;

    procedure Assert_Has_Archive_Index (This_Library : in Full_Name) is
    begin
        Assert_Object_Exists (Pathnames.Archive_Index_For (This_Library));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_No_Archive_Index;
            --
    end Assert_Has_Archive_Index;

    -- *****

    procedure Assert_Object_Does_Not_Exist (This_Object : in Full_Name) is
        --
        The_Object : Directory_Tools.Object.Iterator :=
           Directory_Tools.Naming.Resolution (This_Object);
        --
    begin  
        Assert_Not_Ambiguous (The_Object);
        Assert_Empty (The_Object);
    end Assert_Object_Does_Not_Exist;

    procedure Assert_Catalog_Does_Not_Exist (This_Catalog : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist (This_Catalog);
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Catalog_Already_Exists;
            --
    end Assert_Catalog_Does_Not_Exist;

    procedure Assert_Version_Does_Not_Exist (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist (This_Version);
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Version_Already_Exists;
            --
    end Assert_Version_Does_Not_Exist;

    procedure Assert_Section_Does_Not_Exist (This_Section : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist (This_Section);
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Section_Already_Exists;
            --
    end Assert_Section_Does_Not_Exist;

    procedure Assert_Item_Does_Not_Exist (This_Item : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist (This_Item);
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Item_Already_Exists;
            --
    end Assert_Item_Does_Not_Exist;

    procedure Assert_Has_No_Sections_Context (This_Catalog : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Sections_Context_For (This_Catalog));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Sections_Context;
            --
    end Assert_Has_No_Sections_Context;

    procedure Assert_Has_No_Versions_Context (This_Catalog : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Versions_Context_For (This_Catalog));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Versions_Context;
            --
    end Assert_Has_No_Versions_Context;

    procedure Assert_Has_No_Document_Setup_File (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Document_Setup_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Document_Setup_File;
            --
    end Assert_Has_No_Document_Setup_File;

    procedure Assert_Has_No_Printer_Options_File
                 (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Printer_Options_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Printer_Options_File;
            --
    end Assert_Has_No_Printer_Options_File;

    procedure Assert_Has_No_Data_File (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist (Pathnames.Data_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Data_File;
            --
    end Assert_Has_No_Data_File;

    procedure Assert_Has_No_Browser_Data_File (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Browser_Data_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Browser_Data_File;
            --
    end Assert_Has_No_Browser_Data_File;

    procedure Assert_Has_No_Release_Notice (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Release_Notice_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Release_Notice;
            --
    end Assert_Has_No_Release_Notice;

    procedure Assert_Has_No_Formatted_Release_Notice
                 (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Formatted_Release_Notice_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Formatted_Release_Notice;
            --
    end Assert_Has_No_Formatted_Release_Notice;

    procedure Assert_Has_No_Booklet (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist (Pathnames.Booklet_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Booklet;
            --
    end Assert_Has_No_Booklet;

    procedure Assert_Has_No_Formatted_Booklet (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Formatted_Booklet_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Formatted_Booklet;
            --
    end Assert_Has_No_Formatted_Booklet;

    procedure Assert_Has_No_Browser_View_Name_File
                 (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Browser_View_Name_File_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Browser_View_Name_File;
            --
    end Assert_Has_No_Browser_View_Name_File;

    procedure Assert_Has_No_Browser (This_Version : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Load_Proc_Name_For (This_Version));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Browser;
            --
    end Assert_Has_No_Browser;

    procedure Assert_Has_No_Tape_Contents (This_Version : in Full_Name) is
    begin
        Assert_Has_No_Browser_Data_File (This_Version);
        Assert_Has_No_Browser (This_Version);
        Assert_Has_No_Archive_Data (This_Version);
        Assert_Has_No_Archive_Index (This_Version);
    end Assert_Has_No_Tape_Contents;

    procedure Assert_Has_No_Archive_Data (This_Library : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Archive_Data_For (This_Library));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Archive_Data;
            --
    end Assert_Has_No_Archive_Data;

    procedure Assert_Has_No_Archive_Index (This_Library : in Full_Name) is
    begin
        Assert_Object_Does_Not_Exist
           (Pathnames.Archive_Index_For (This_Library));
        --
    exception
        when Ambiguous_Name =>
            raise;
        when others =>
            raise Has_Archive_Index;
            --
    end Assert_Has_No_Archive_Index;

end Assertions;