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

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 text, decimal_places integer default 2) returns void as
$$
	insert into campsite_type_option_cost (campsite_type_option_id, season_id, cost)
	values (option_id, season_id, parse_price(cost, decimal_places))
	on conflict (campsite_type_option_id, season_id) do update
	set cost = excluded.cost
	;
$$
	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;
