-- Prosody MySQL Database Initialization Script

USE prosody;

-- Create tables for Prosody storage

CREATE TABLE IF NOT EXISTS `prosody` (
  `host` text,
  `user` text,
  `store` text,
  `key` text,
  `type` text,
  `value` mediumtext
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `prosody_auth` (
  `username` varchar(255) NOT NULL,
  `host` varchar(255) NOT NULL,
  `password` varchar(255),
  `created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`username`, `host`),
  INDEX (`host`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `prosody_roster` (
  `username` varchar(255) NOT NULL,
  `host` varchar(255) NOT NULL,
  `jid` varchar(255) NOT NULL,
  `name` varchar(255),
  `subscription` varchar(10),
  `ask` varchar(10),
  `created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`username`, `host`, `jid`),
  INDEX (`host`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Insert initial admin user
INSERT INTO `prosody_auth` (`username`, `host`, `password`)
VALUES ('mish', 'xmpp.guschin.info', '3X`V');

-- Prosody will handle the rest of the initialization automatically
