-- Deploy camper:payment to pg
-- requires: roles
-- requires: schema_camper
-- requires: company
-- requires: campsite_type
-- requires: payment_status
-- requires: positive_integer
-- requires: nonnegative_integer

begin;

set search_path to camper, public;

create table payment (
	payment_id integer generated by default as identity primary key,
	company_id integer not null references company,
	slug uuid not null unique default gen_random_uuid(),
	campsite_type_id integer not null references campsite_type,
	arrival_date date not null,
	departure_date date not null constraint departure_after_arrival check (departure_date > arrival_date),
	subtotal_nights nonnegative_integer not null,
	number_adults positive_integer not null,
	subtotal_adults nonnegative_integer not null,
	number_teenagers nonnegative_integer not null,
	subtotal_teenagers nonnegative_integer not null,
	number_children nonnegative_integer not null,
	subtotal_children nonnegative_integer not null,
	number_dogs nonnegative_integer not null,
	subtotal_dogs nonnegative_integer not null,
	subtotal_tourist_tax nonnegative_integer not null,
	total nonnegative_integer not null,
	zone_preferences text not null,
	payment_status text not null default 'draft' references payment_status,
	created_at timestamp with time zone not null default current_timestamp,
	updated_at timestamp with time zone not null default current_timestamp
);

grant select, insert, update on table payment to guest;
grant select, insert, update on table payment to employee;
grant select, insert, update, delete on table payment to admin;

commit;
