CREATE DATABASE Icarus;

USE Icarus;

CREATE TABLE CoverArt (
    Id INT NOT NULL AUTO_INCREMENT,
    SongTitle TEXT NOT NULL,
    ImagePath TEXT NOT NULL,

    PRIMARY KEY (Id)
);

CREATE TABLE Album (
    Id INT NOT NULL AUTO_INCREMENT,
    Title TEXT NOT NULL,
    Artist TEXT NOT NULL,
    Year INT NOT NULL,

    PRIMARY KEY (Id)
);

CREATE TABLE Artist (
    Id INT NOT NULL AUTO_INCREMENT,
    Artist TEXT NOT NULL,

    PRIMARY KEY (Id)
);

CREATE TABLE Genre (
    Id INT NOT NULL AUTO_INCREMENT,
    Category TEXT NOT NULL,

    PRIMARY KEY (Id)
);


CREATE TABLE Song (
    Id INT NOT NULL AUTO_INCREMENT,
    Title TEXT NOT NULL,
    Artist TEXT NOT NULL,
    Album TEXT NOT NULL,
    AlbumArtist TEXT NOT NULL,
    Genre TEXT NOT NULL,
    Year INT NOT NULL,
    Duration INT NOT NULL,
    Track INT NOT NULL,
    TrackCount INT NOT NULL,
    Disc INT NOT NULL,
    DiscCount INT NOT NULL,
    SongDirectory TEXT NOT NULL,
    Filename TEXT NOT NULL,
    CoverArtId INT NOT NULL,
    ArtistId INT NOT NULL,
    AlbumId INT NOT NULL,
    GenreId INT NOT NULL,
    DateCreated DATETIME DEFAULT CURRENT_TIMESTAMP,

    PRIMARY KEY (Id),
    CONSTRAINT FK_Song_CoverArtId FOREIGN KEY (CoverArtId) REFERENCES CoverArt (Id),
    CONSTRAINT FK_Song_ArtistId FOREIGN KEY (ArtistId) REFERENCES Artist (Id),
    CONSTRAINT FK_Song_AlbumId FOREIGN KEY (AlbumId) REFERENCES Album (Id),
    CONSTRAINT FK_Song_GenreId FOREIGN KEY (GenreId) REFERENCES Genre (Id)
);

CREATE TABLE User (
    Id INT NOT NULL AUTO_INCREMENT,
    Firstname TEXT NOT NULL,
    Lastname TEXT NOT NULL,
    Email TEXT NOT NULL,
    Phone TEXT NOT NULL,
    Username TEXT NOT NULL,
    Password TEXT NOT NULL,
    DateCreated DATETIME DEFAULT CURRENT_TIMESTAMP,
    Status TEXT DEFAULT 'Active',
    LastLogin DATETIME NULL,

    PRIMARY KEY (Id)
);
