with Direct_Io;
with Form;
with String_Utilities;
with Cmvc;
package body Cm_Generic is  
    package Su renames String_Utilities;
    Wo        : constant String := Work_Order_Path;
    Task_List : constant String := Wo & ".project_tasks";

    type Form_Rec is
        record
            The_Form   : Form.Form_Definition;
            Is_Defined : Boolean := False;
            Start_Item : Items;
            End_Item   : Items;
        end record;

    Form_Array : array (Forms) of Form_Rec;

    procedure Create_Work_Order (Title : String := ">>NOTES<<") is separate;

    procedure Edit (Work_Order : String := ">>ORDER NAME<<";
                    For_Form   : Forms) is separate;

    procedure Check_In (What_Object : String := "<CURSOR>";
                        Comments    : String := ">>COMMENTS<<";
                        Work_Order  : String := ">>ORDER NAME<<") is
        Wo : constant String := Work_Order_Path & '.' & Work_Order;
    begin
        Cmvc.Check_In (What_Object => What_Object,
                       Comments    => Comments,
                       Work_Order  => Wo,
                       Response    => "<PROFILE>");

    end Check_In;

    procedure Check_Out (What_Object : String := "<CURSOR>";
                         Comments    : String := ">>COMMENTS<<";
                         Work_Order  : String := ">>ORDER NAME<<") is

        Wo : constant String := Work_Order_Path & '.' & Work_Order;

    begin
        Cmvc.Check_Out (What_Object => What_Object,
                        Comments => Comments,
                        Allow_Demotion => False,
                        Allow_Implicit_Accept_Changes => True,
                        Expected_Check_In_Time => "<TOMORROW>",
                        Work_Order => Wo,
                        Response => "<PROFILE>");

    end Check_Out;

    procedure Display (Work_Order : String := ">>ORDER NAME<<") is separate;

    procedure Show_Work_Orders (For_Work_List : String :=
                                   ">>WORK LIST<<") is separate;

    procedure Show_Info (For_Configuration : String := "<CURSOR>") is separate;

    package body Form_Definition is

        procedure Add (Header : Items; Prompt : String; To_Form : Forms) is
        begin
            if not Form_Array (To_Form).Is_Defined then
                Form_Array (To_Form).Is_Defined := True;
                Form_Array (To_Form).The_Form   := Form.Make;
                Form_Array (To_Form).Start_Item := Header;
                Form_Array (To_Form).End_Item   := Header;

            else
                Form_Array (To_Form).End_Item := Header;
            end if;
            Form.Add (Item    => Su.Capitalize (Items'Image (Header)),
                      Prompt  => Prompt,
                      To_Form => Form_Array (To_Form).The_Form);

        end Add;
    end Form_Definition;

    package body Initialization is
        procedure Init_Index is
            package Dio is new Direct_Io (Integer);
            use Dio;

            Wo_Index : constant String := Work_Order_Path & ".wo_index";
            Handle   : Dio.File_Type;
            I        : Integer         := 0;

        begin

            Dio.Create (File => Handle, Mode => Out_File, Name => Wo_Index);
            Dio.Write (File => Handle, Item => I, To => 1);
            Dio.Close (File => Handle);

        end Init_Index;
    end Initialization;
end Cm_Generic;