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

begin;

set search_path to camper, public;

drop function if exists edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, 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, bookable_nights int4range, overflow_allowed boolean, ask_zone_preferences 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
	  , bookable_nights = edit_campsite_type.bookable_nights
	  , overflow_allowed = edit_campsite_type.overflow_allowed
	  , ask_zone_preferences = edit_campsite_type.ask_zone_preferences
	  , 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, int4range, boolean, boolean, boolean) from public;
grant execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean) to admin;

commit;
