CREATE TABLE IF NOT EXISTS notification_role_preferences (
  id SERIAL PRIMARY KEY,
  email_type VARCHAR(50) NOT NULL,
  role VARCHAR(20) NOT NULL,
  enabled BOOLEAN NOT NULL DEFAULT true,
  created_at TIMESTAMP DEFAULT NOW(),
  updated_at TIMESTAMP DEFAULT NOW(),
  UNIQUE (email_type, role)
);

INSERT INTO notification_role_preferences (email_type, role, enabled)
VALUES
  ('documento_subido','owner',true),
  ('documento_subido','supervisor',true),
  ('documento_subido','auxiliar',true),
  ('documento_subido','cliente',true),
  ('weekly_update','owner',true),
  ('weekly_update','supervisor',true),
  ('weekly_update','auxiliar',true),
  ('weekly_update','cliente',true),
  ('subscription_expiring','owner',true),
  ('subscription_expiring','supervisor',true),
  ('subscription_expiring','auxiliar',true),
  ('subscription_expiring','cliente',true),
  ('recordatorio_fiscal','owner',true),
  ('recordatorio_fiscal','supervisor',true),
  ('recordatorio_fiscal','auxiliar',true),
  ('recordatorio_fiscal','cliente',true),
  ('alertas_nuevas','owner',true),
  ('alertas_nuevas','supervisor',true),
  ('alertas_nuevas','auxiliar',true),
  ('alertas_nuevas','cliente',true),
  ('recordatorio_proximo','owner',true),
  ('recordatorio_proximo','supervisor',true),
  ('recordatorio_proximo','auxiliar',true),
  ('recordatorio_proximo','cliente',true)
ON CONFLICT (email_type, role) DO NOTHING;
