-- Deploy camper:set_campsite_type_option_cost to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_type_option_cost
-- requires: parse_price

begin;

set search_path to camper, public;

drop function if exists set_campsite_type_option_cost(integer, integer, text, integer);

create or replace function set_campsite_type_option_cost(option_id integer, season_id integer, cost_per_night text, decimal_places integer default 2) returns void as
$$
	insert into campsite_type_option_cost (campsite_type_option_id, season_id, cost_per_night)
	values (option_id, season_id, parse_price(cost_per_night, decimal_places))
	on conflict (campsite_type_option_id, season_id) do update
	set cost_per_night = excluded.cost_per_night
	;
$$
	language sql
;

revoke execute on function set_campsite_type_option_cost(integer, integer, text, integer) from public;
grant execute on function set_campsite_type_option_cost(integer, integer, text, integer) to admin;

commit;
