create or replace procedure add_person (
  p_firstname text,
  p_lastname text,
  p_birthdate date
)
language plpgsql
as $$
declare
  v_holder_id bigint;
begin
   
    insert into holder(type) values ('PERSON')
    returning id into v_holder_id;

    insert into person(id, firstname, lastname, birthdate)
    values (v_holder_id, p_firstname, p_lastname, p_birthdate);

    raise notice 'Titulaire créé : % = % %',
         v_holder_id, p_firstname, p_lastname;
end;
$$;

create or replace procedure add_bank (
  name text
)
language plpgsql
as $$
declare
  v_holder_id bigint;
begin
   
    insert into holder(type) values ('BANK')
    returning id into v_holder_id;

    insert into bank(id, name)
    values (v_holder_id, p_name);

    raise notice 'Titulaire créé : % = %',
         v_holder_id, p_name;
end;
$$;

create or replace procedure add_company (
 p_name text, 
 p_registration_number text, 
 p_created_at date
)
language plpgsql
as $$
declare
  v_holder_id bigint;
begin
   
    insert into holder(type) values ('COMPANY')
    returning id into v_holder_id;

    insert into company(id, name, registration_number, created_at)
    values (v_holder_id, p_name, p_registration_number, p_created_at);

    raise notice 'Titulaire créé : % = % %',
         v_holder_id, p_name, p_registration_number;
end;
$$;
