-- Deploy camper:set_campsite_type_pet_cost to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_type
-- requires: campsite_type_pet_cost
-- requires: parse_price

begin;

set search_path to camper, public;

create or replace function set_campsite_type_pet_cost(slug uuid, cost text) returns void as
$$
	insert into campsite_type_pet_cost (campsite_type_id, cost_per_night)
	select campsite_type_id, parse_price(cost, decimal_digits)
	from campsite_type
		join company using (company_id)
		join currency using (currency_code)
	where campsite_type.slug = set_campsite_type_pet_cost.slug
	on conflict (campsite_type_id) do update
	set cost_per_night = excluded.cost_per_night
	;
$$
	language sql
;

revoke execute on function set_campsite_type_pet_cost(uuid, text) from public;
grant execute on function set_campsite_type_pet_cost(uuid, text) to admin;

commit;
