--
-- pa_collection__new/7
--
create or replace function pa_collection__new(
  integer,
  integer,
  character varying,
  timestamp with time zone,
  integer,
  character varying,
  integer
) returns int4 as $$

declare
  p_collection_id                       alias for $1;       -- default null
  p_owner_id                            alias for $2;       -- default null
  p_title                               alias for $3;
  p_creation_date                       alias for $4;       -- default now()
  p_creation_user                       alias for $5;       -- default null
  p_creation_ip                         alias for $6;       -- default null
  p_context_id                          alias for $7;       -- default null
  v_collection_id                                     pa_collections.collection_id%TYPE;
begin
        v_collection_id := acs_object__new (
                p_collection_id,
                'photo_collection',
                p_creation_date,
                p_creation_user,
                p_creation_ip,
                p_context_id
        );

        insert into pa_collections
          (collection_id, owner_id, title)
        values
          (v_collection_id, p_owner_id, p_title);

        PERFORM acs_permission__grant_permission(
          v_collection_id,
          p_owner_id,
          'admin'
    );

    return v_collection_id;

end;$$ language plpgsql;