-- Deploy camper:translate_legal_text to pg
-- requires: roles
-- requires: schema_camper
-- requires: legal_text_i18n

begin;

set search_path to camper, public;

create or replace function translate_legal_text(company_id integer, slug text, lang_tag text, name text, content text) returns void as
$$
	insert into legal_text_i18n (company_id, slug, lang_tag, name, content)
	values (company_id, slug, lang_tag, coalesce(name, ''), xmlparse(content coalesce(content, '')))
	on conflict (company_id, slug, lang_tag) do update
	set name = excluded.name
	  , content = excluded.content
	;
$$
	language sql
;

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

commit;
