-- Deploy camper:edit_campsite_type to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_type
-- requires: company

begin;

set search_path to camper, public;

drop function if exists edit_campsite_type(uuid, integer, text, text, text, text, text, text, integer, boolean, boolean);

create or replace function edit_campsite_type(slug uuid, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, dogs_allowed boolean, active boolean) returns uuid as
$$
	update campsite_type
	set name = edit_campsite_type.name
	  , spiel = xmlparse(content edit_campsite_type.spiel)
	  , description = xmlparse(content edit_campsite_type.description)
	  , info = xmlparse(content edit_campsite_type.info)
	  , additional_info = xmlparse(content edit_campsite_type.additional_info)
	  , check_in = edit_campsite_type.check_in
	  , check_out = edit_campsite_type.check_out
	  , facilities = xmlparse(content edit_campsite_type.facilities)
	  , media_id = coalesce(edit_campsite_type.media_id, campsite_type.media_id)
	  , max_campers = edit_campsite_type.max_campers
	  , dogs_allowed = edit_campsite_type.dogs_allowed
	  , active = edit_campsite_type.active
	where slug = edit_campsite_type.slug
	returning slug;
$$
language sql
;

revoke execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean) from public;
grant execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean) to admin;

commit;
