-- Room Reservation Package
--
-- @author Deds Castillo (deds@infiniteinfo.com)
-- @creation-date 2002-08-28
-- @cvs-id $Id: facilities-create.sql,v 1.1.4.2 2004/07/12 23:04:25 jader Exp $
--
-- Total rewrite though some
-- concepts were taken from the old
-- ACS3.x Room Reservation package


-- let's do the table stuff
create table rr_facilities (
    facility_id                     integer
                                    constraint rr_facilities_facility_id_nn
                                    not null
                                    constraint rr_facilities_facility_id_fk
                                    references acs_objects (object_id)
                                    constraint rr_facilities_facility_id_pk
                                    primary key,
    name                            varchar(200)
                                    constraint rr_facilities_name_un
                                    unique
                                    constraint rr_facilities_name_nn
                                    not null,
    description                     varchar(400),
    enabled_p                       char(1)
                                    default 't'
                                    constraint rr_facilities_enabled_p_nn
                                    not null
                                    constraint rr_facilities_enabled_p_ck
                                    check (enabled_p in ('t','f')),
    -- to keep track of instances
    package_id                      integer
                                    constraint rr_facilities_package_id_nn
                                    not null
);

-- let's do the views stuff
create view rr_facilities_enabled
as
    select *
    from rr_facilities
    where enabled_p = 't';

create view rr_facilities_disabled
as
    select *
    from rr_facilities
    where enabled_p = 'f';

-- let's create our object
create function inline_0 ()
returns integer as'
begin
    perform acs_object_type__create_type(
        ''rr_facility'',         -- object_type
        ''Facility'',            -- pretty_name
        ''Facilities'',          -- pretty_plural
        ''acs_object'',          -- supertype
        ''rr_facilities'',       -- table_name
        ''facility_id'',         -- id_column
        ''rr_facilities'',       -- package_name
        ''f'',                   -- abstract_p
        null,                    -- type_extensions_table
        ''rr_facilities__name''  -- name_method
    );

    return null;
end;' language 'plpgsql';

select inline_0();
drop function inline_0();
