-- Daily Quote app schema

CREATE TABLE IF NOT EXISTS users (
  id SERIAL PRIMARY KEY,
  sub TEXT UNIQUE NOT NULL,
  email TEXT,
  display_name TEXT,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE IF NOT EXISTS quotes (
  id SERIAL PRIMARY KEY,
  text TEXT NOT NULL,
  author TEXT NOT NULL DEFAULT 'Unknown',
  submitted_by INTEGER REFERENCES users(id) ON DELETE SET NULL,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE IF NOT EXISTS favorites (
  user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  quote_id INTEGER NOT NULL REFERENCES quotes(id) ON DELETE CASCADE,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
  PRIMARY KEY (user_id, quote_id)
);

INSERT INTO quotes (text, author) VALUES
('The only way to do great work is to love what you do.', 'Steve Jobs'),
('Life is what happens to you while you''re busy making other plans.', 'John Lennon'),
('In the middle of difficulty lies opportunity.', 'Albert Einstein'),
('It does not matter how slowly you go as long as you do not stop.', 'Confucius'),
('The journey of a thousand miles begins with a single step.', 'Lao Tzu'),
('That which does not kill us makes us stronger.', 'Friedrich Nietzsche'),
('Whether you think you can or you think you can''t, you''re right.', 'Henry Ford'),
('The best way to predict the future is to invent it.', 'Alan Kay'),
('Simplicity is the ultimate sophistication.', 'Leonardo da Vinci'),
('Not all those who wander are lost.', 'J.R.R. Tolkien'),
('The unexamined life is not worth living.', 'Socrates'),
('I think, therefore I am.', 'René Descartes'),
('What we think, we become.', 'Buddha'),
('The only impossible journey is the one you never begin.', 'Tony Robbins'),
('Believe you can and you''re halfway there.', 'Theodore Roosevelt'),
('It always seems impossible until it''s done.', 'Nelson Mandela'),
('The future belongs to those who believe in the beauty of their dreams.', 'Eleanor Roosevelt'),
('Success is not final, failure is not fatal: it is the courage to continue that counts.', 'Winston Churchill'),
('You miss 100% of the shots you don''t take.', 'Wayne Gretzky'),
('The only limit to our realization of tomorrow is our doubts of today.', 'Franklin D. Roosevelt'),
('Do one thing every day that scares you.', 'Eleanor Roosevelt'),
('Everything you''ve ever wanted is on the other side of fear.', 'George Addair'),
('Act as if what you do makes a difference. It does.', 'William James'),
('Turn your wounds into wisdom.', 'Oprah Winfrey'),
('Your time is limited, so don''t waste it living someone else''s life.', 'Steve Jobs'),
('The mind is everything. What you think you become.', 'Buddha'),
('Twenty years from now you will be more disappointed by the things you didn''t do than by the ones you did do.', 'Mark Twain'),
('Either you run the day, or the day runs you.', 'Jim Rohn'),
('The only person you are destined to become is the person you decide to be.', 'Ralph Waldo Emerson'),
('Go confidently in the direction of your dreams. Live the life you have imagined.', 'Henry David Thoreau'),
('Do not wait to strike till the iron is hot; but make it hot by striking.', 'William Butler Yeats'),
('When one door of happiness closes, another opens.', 'Helen Keller'),
('Everything has beauty, but not everyone can see.', 'Confucius'),
('You can never cross the ocean until you have the courage to lose sight of the shore.', 'Christopher Columbus'),
('Change your thoughts and you change your world.', 'Norman Vincent Peale'),
('Nothing is impossible, the word itself says ''I''m possible''!', 'Audrey Hepburn'),
('The best revenge is massive success.', 'Frank Sinatra'),
('If you set your goals ridiculously high and it''s a failure, you will fail above everyone else''s success.', 'James Cameron'),
('Life is 10% what happens to you and 90% how you react to it.', 'Charles R. Swindoll'),
('The way to get started is to quit talking and begin doing.', 'Walt Disney'),
('Don''t let yesterday take up too much of today.', 'Will Rogers')
ON CONFLICT DO NOTHING;
