CREATE TABLE admin (
	AdminID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	Name CHAR(50) NOT NULL,
	Password CHAR(50) NOT NULL,
	Email CHAR(50) NOT NULL,
	AccountType INT UNSIGNED NOT NULL,
	ActivateStatus INT UNSIGNED NOT NULL
);

CREATE TABLE maestro (
	MaestroID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	Name CHAR(50) NOT NULL,
	Password CHAR(50) NOT NULL,
	Email CHAR(50) NOT NULL,
	AccountType INT UNSIGNED NOT NULL,
	ActivateStatus INT UNSIGNED NOT NULL,
	AvailableActivateDateTime DATETIME NOT NULL,
	PlayerCount INT UNSIGNED NOT NULL,
	AcceptClausesDateTime DATETIME NOT NULL,
	MaestroTestID INT UNSIGNED
);

CREATE TABLE maestro_upgrade (
	MaestroUpgradeID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	RegisteredAccountType INT UNSIGNED NOT NULL,
	RequestedAccountType INT UNSIGNED NOT NULL,
	RequestedDateTime DATETIME NOT NULL,
	Status INT UNSIGNED NOT NULL,
	MaestroID INT UNSIGNED NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID)
);

CREATE TABLE player (
	PlayerID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	MaestroID INT UNSIGNED NOT NULL,
	Name CHAR(50) NOT NULL,
	EnterCode CHAR(8) NOT NULL,
	AccountType INT UNSIGNED NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID)
);



CREATE TABLE app (
	AppID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	AppName CHAR(40) NOT NULL,
	KoreanName CHAR(40) NOT NULL,
	AppType INT UNSIGNED NOT NULL,
	Status INT UNSIGNED NOT NULL,
	HowToPlay TEXT NOT NULL
);

CREATE TABLE active_app (
	ActiveAppID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	MaestroID INT UNSIGNED NOT NULL,
	AppID INT UNSIGNED NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID),
	FOREIGN KEY (AppID) REFERENCES app(AppID)
);



CREATE TABLE best_record (
	BestRecordID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	MaestroID INT UNSIGNED NOT NULL,
	AppID INT UNSIGNED NOT NULL,
	PlayerID INT UNSIGNED NOT NULL,
	BestRecord FLOAT NOT NULL,
	RecordDateTime DATETIME NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID),
	FOREIGN KEY (AppID) REFERENCES app(AppID),
	FOREIGN KEY (PlayerID) REFERENCES player(PlayerID)
);

CREATE TABLE app_highest_record (
	AppHighestRecordID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	MaestroID INT UNSIGNED NOT NULL,
	AppID INT UNSIGNED NOT NULL,
	PlayerID INT UNSIGNED NOT NULL,
	HighestRecord FLOAT NOT NULL,
	RecordDateTime DATETIME NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID),
	FOREIGN KEY (AppID) REFERENCES app(AppID),
	FOREIGN KEY (PlayerID) REFERENCES player(PlayerID)
);

CREATE TABLE ranking (
	RankingID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	MaestroID INT UNSIGNED NOT NULL,
	AppID INT UNSIGNED NOT NULL,
	RankingType INT UNSIGNED NOT NULL,
	Rank INT UNSIGNED NOT NULL,
	PlayerID INT UNSIGNED NOT NULL,

	FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID),
	FOREIGN KEY (AppID) REFERENCES app(AppID),
	FOREIGN KEY (PlayerID) REFERENCES player(PlayerID)
);

CREATE TABLE banned_word (
	BannedWordID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	Word CHAR(50) NOT NULL
);

CREATE TABLE maestro_log (
	MaestroLogID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	Type CHAR(50) NOT NULL,
	LogDateTime DATETIME NOT NULL,
	MaestroID INT UNSIGNED NOT NULL,
	Remark CHAR(100) NOT NULL
);
