begin;

create table if not exists public.senkredi_runtime_settings (
  key text primary key default 'default' check (key = 'default'),
  app_name text not null default 'SenKredi',
  business_name text not null default 'SenKredi',
  website_url text not null default '',
  support_email text not null default '',
  support_phone text not null default '',
  support_whatsapp text not null default '',
  wave_number text not null default '',
  orange_money_number text not null default '',
  subscription_price_fcfa integer not null default 10000 check (subscription_price_fcfa >= 0),
  payment_instructions text not null default '',
  updated_at timestamptz not null default now()
);

alter table public.senkredi_runtime_settings enable row level security;

revoke all on table public.senkredi_runtime_settings from public;
grant all on table public.senkredi_runtime_settings to service_role;

drop policy if exists "runtime_settings_select_none" on public.senkredi_runtime_settings;
create policy "runtime_settings_select_none"
on public.senkredi_runtime_settings
for select
to authenticated
using (false);

drop policy if exists "runtime_settings_insert_none" on public.senkredi_runtime_settings;
create policy "runtime_settings_insert_none"
on public.senkredi_runtime_settings
for insert
to authenticated
with check (false);

drop policy if exists "runtime_settings_update_none" on public.senkredi_runtime_settings;
create policy "runtime_settings_update_none"
on public.senkredi_runtime_settings
for update
to authenticated
using (false)
with check (false);

insert into public.senkredi_runtime_settings (
  key,
  app_name,
  business_name,
  website_url,
  support_email,
  support_phone,
  support_whatsapp,
  wave_number,
  orange_money_number,
  subscription_price_fcfa,
  payment_instructions,
  updated_at
)
values (
  'default',
  'SenKredi',
  'SenKredi',
  '',
  '',
  '',
  '',
  '',
  '',
  10000,
  '',
  now()
)
on conflict (key) do nothing;

commit;
