USE friendBook;

CREATE TABLE login(
    username varchar(25),
    pword varchar(25),
    primary key(username));

CREATE TABLE contacts(
    username varchar(25),
    fname varchar(25),
    lname varchar(25),
    primary key(username),
    foreign key(username) references login(username));

CREATE TABLE messages(
    messageID int,
    sender varchar(25),
    recipient varchar(25),
    message text,
    date date,
    haveread varchar(1),
    primary key(messageID),
    foreign key(sender) references contacts(username),
    foreign key(recipient) references contacts(username));

CREATE TABLE friendList(
    username varchar(25),
    friend varchar(25),
    confirm boolean);

INSERT INTO login
    (username, pword)
VALUES 
    ('user1', 'password1'),
    ('user2', 'password2');

INSERT INTO contacts
    (username, fname, lname)
VALUES
    ('user1', 'num1', 'uno'),
    ('user2', 'num2', 'dos');

INSERT INTO messages
    (messageID, sender, recipient, message, date, haveread)
VALUES
    ('1', 'user1', 'user2', 'hello, how are you', now(), 'Y'),
    ('2', 'user2', 'user1', 'im doing good, thanks', now(), 'N');