-- Общая рекомендация - расписать use-case'ы

CREATE SCHEMA `up_and_down` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE `up_and_down`.`users` (
    `guid` CHAR(36) NOT NULL,
    `login` VARCHAR(128) NOT NULL,
    `hashed_password` TEXT NOT NULL,
    PRIMARY KEY (`guid`),
    UNIQUE INDEX `guid_UNIQUE` (`guid` ASC)
);

CREATE TABLE `up_and_down`.`mania` (
	`level` INT1 NOT NULL,
    `description` TEXT NOT NULL,
    PRIMARY KEY (`level`)
);

CREATE TABLE `up_and_down`.`depressions` (
	`level` INT1 NOT NULL,
    `description` TEXT NOT NULL,
    PRIMARY KEY (`level`)
);

CREATE TABLE `up_and_down`.`moods` (
	`level` INT1 NOT NULL,
    `description` TEXT NOT NULL,
    PRIMARY KEY (`level`)
);

CREATE TABLE `up_and_down`.`activities` (
	`level` INT1 NOT NULL,
    `description` TEXT NOT NULL,
    PRIMARY KEY (`level`)
);

CREATE TABLE `up_and_down`.`appetites` (
	`level` INT1 NOT NULL,
    `description` TEXT NOT NULL,
    PRIMARY KEY (`level`)
);

CREATE TABLE `up_and_down`.`dreams` (
	`level` INT1 NOT NULL,
    `description` TEXT NOT NULL,
    PRIMARY KEY (`level`)
);

CREATE TABLE `up_and_down`.`anxiety` (
	`level` INT1 NOT NULL,
    `description` TEXT NOT NULL,
    PRIMARY KEY (`level`)
);

CREATE TABLE `up_and_down`.`diaries` (
    `guid` CHAR(36) NOT NULL,
    `user_guid` CHAR(36) NOT NULL,
    `time` DATETIME NOT NULL,
    `mania_level` INT1 NOT NULL,
    `depression_level` INT1 NOT NULL,
    `mood_level` INT1 NOT NULL,
    `activity_level` INT1 NOT NULL,
    `appetite_level` INT1 NOT NULL,
    `dream_level` INT1 NOT NULL,
    `anxiety_level` INT1 NOT NULL,
    PRIMARY KEY (`guid`),
    FOREIGN KEY (`user_guid`) REFERENCES `users`(`guid`),
    FOREIGN KEY (`mania_level`) REFERENCES `mania`(`level`),
    FOREIGN KEY (`depression_level`) REFERENCES `depressions`(`level`),
    FOREIGN KEY (`mood_level`) REFERENCES `moods`(`level`),
    FOREIGN KEY (`activity_level`) REFERENCES `activities`(`level`),
    FOREIGN KEY (`appetite_level`) REFERENCES `appetites`(`level`),
    FOREIGN KEY (`dream_level`) REFERENCES `dreams`(`level`),
    FOREIGN KEY (`anxiety_level`) REFERENCES `anxiety`(`level`),
    UNIQUE INDEX `guid_UNIQUE` (`guid` ASC)
);

CREATE TABLE `up_and_down`.`medications` (
	`guid` CHAR(36) NOT NULL,
    `name` TEXT NOT NULL,
    `dose` int8 NOT NULL,
    `unit` CHAR(30),
    `is_urgent` BOOL NOT NULL,
    PRIMARY KEY (`guid`)
);

CREATE TABLE `up_and_down`.`set_of_medications_guids` (
	`guid` CHAR(36) NOT NULL,
    PRIMARY KEY (`guid`)
);

CREATE TABLE `up_and_down`.`set_of_medications` (
	`guid` CHAR(36) NOT NULL,
    `set_guid` CHAR(36) NOT NULL,
    `medication_guid` CHAR(36) NOT NULL,
    PRIMARY KEY (`guid`),
    FOREIGN KEY (`medication_guid`) REFERENCES `medications`(`guid`),
    FOREIGN KEY (`set_guid`) REFERENCES `set_of_medications_guids`(`guid`)
);

CREATE TABLE `up_and_down`.`diaries_to_sets_of_medications` (
	`guid` CHAR(36) NOT NULL,
    `set_of_medications_guid` CHAR(36) NOT NULL,
    `diary_guid` CHAR(36) NOT NULL,
    PRIMARY KEY (`guid`),
    FOREIGN KEY (`set_of_medications_guid`) REFERENCES `set_of_medications_guids`(`guid`),
    FOREIGN KEY (`diary_guid`) REFERENCES `diaries`(`guid`)
);

-- insert constants
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (1, 'Полное отсутствие мании');
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (2, 'Слегка приподнятое настроение');
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (3, 'Хорошее настроение');
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (4, 'Очень хорошее настроение, но в рамках разумного');
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (5, 'Гипомания I, характерная для циклотимии - приятная эйфория, повышенная активность');
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (6, 'Гипомания II, характерная для БАР II - все, что в предыдущем пункте + белеет в глазах');
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (7, 'Мания I - периодический не сильный отрыв от реальности');
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (8, 'Мания II - сопровождается бредом и галлюцинациями - неадекватная речь');
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (9, 'Мания III - сопровождается бредом и галлюцинациями - неадекватное поведение');
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (10, 'Мания IV - сопровождается бредом и галлюцинациями - человек опасен для себя и других');

INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (1, 'Депрессия I');
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (2, 'Депрессия II');
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (3, 'Депрессия III');
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (4, 'Депрессия IV');
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (5, 'Депрессия V');
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (6, 'Депрессия VI');
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (7, 'Депрессия VII');
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (8, 'Депрессия VIII');
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (9, 'Депрессия IX');
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (10, 'Депрессия X');

INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (1, 'Настроение I');
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (2, 'Настроение II');
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (3, 'Настроение III');
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (4, 'Настроение IV');
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (5, 'Настроение V');
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (6, 'Настроение VI');
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (7, 'Настроение VII');
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (8, 'Настроение VIII');
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (9, 'Настроение IX');
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (10, 'Настроение X');

INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (1, 'Активность I');
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (2, 'Активность II');
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (3, 'Активность III');
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (4, 'Активность IV');
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (5, 'Активность V');
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (6, 'Активность VI');
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (7, 'Активность VII');
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (8, 'Активность VIII');
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (9, 'Активность IX');
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (10, 'Активность X');

INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (1, 'Аппетит I');
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (2, 'Аппетит II');
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (3, 'Аппетит III');
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (4, 'Аппетит IV');
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (5, 'Аппетит V');
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (6, 'Аппетит VI');
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (7, 'Аппетит VII');
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (8, 'Аппетит VIII');
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (9, 'Аппетит IX');
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (10, 'Аппетит X');

INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (1, 'Сон I');
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (2, 'Сон II');
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (3, 'Сон III');
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (4, 'Сон IV');
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (5, 'Сон V');
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (6, 'Сон VI');
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (7, 'Сон VII');
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (8, 'Сон VIII');
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (9, 'Сон IX');
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (10, 'Сон X');

INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (1, 'Тревога I');
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (2, 'Тревога II');
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (3, 'Тревога III');
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (4, 'Тревога IV');
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (5, 'Тревога V');
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (6, 'Тревога VI');
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (7, 'Тревога VII');
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (8, 'Тревога VIII');
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (9, 'Тревога IX');
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (10, 'Тревога X');

-- Заполнение пользователями
INSERT INTO `up_and_down`.`users` (`guid`, `login`, `hashed_password`) VALUES ('ab555fcb-b9ee-45f4-9de8-8f16daa5d03b', 'login1', 'Qwerty12345');
INSERT INTO `up_and_down`.`users` (`guid`, `login`, `hashed_password`) VALUES ('56b7c993-392f-41f8-adb1-9766842dc5fd', 'login2', 'AVALON123456');
INSERT INTO `up_and_down`.`users` (`guid`, `login`, `hashed_password`) VALUES ('a243b5f2-e265-4c25-82a9-dde4cc70643f', 'login3', 'Zxcvb123456');
INSERT INTO `up_and_down`.`users` (`guid`, `login`, `hashed_password`) VALUES ('51351bb1-7563-479d-a8e9-201d0ff934c2', 'login4', 'Sadly846612');
INSERT INTO `up_and_down`.`users` (`guid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b6', 'login5', 'Qwerty12345');
