PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE Types (id INTEGER PRIMARY KEY, Name TEXT);
INSERT INTO Types VALUES(1,'attachment');
INSERT INTO Types VALUES(2,'dog');
INSERT INTO Types VALUES(3,'food');
INSERT INTO Types VALUES(4,'movement');
INSERT INTO Types VALUES(5,'personal');
INSERT INTO Types VALUES(6,'sled');
INSERT INTO Types VALUES(7,'utility');
INSERT INTO Types VALUES(8,'damage');

CREATE TABLE Decks (id INTEGER PRIMARY KEY, Name TEXT);
INSERT INTO Decks VALUES(1,'starter1');
INSERT INTO Decks VALUES(2,'starter2');
INSERT INTO Decks VALUES(3,'starter3');
INSERT INTO Decks VALUES(4,'starter4');
INSERT INTO Decks VALUES(10,'survival');
INSERT INTO Decks VALUES(11,'race');
INSERT INTO Decks VALUES(20,'legendary');
INSERT INTO Decks VALUES(21,'damage');

CREATE TABLE Effects (id INTEGER PRIMARY KEY, Name TEXT, Command TEXT);
INSERT INTO Effects VALUES(1,'Day Draw','\daydraw{#}');
INSERT INTO Effects VALUES(2,'Draw','\draw{#}');
INSERT INTO Effects VALUES(3,'Supply','\supply{#}');
INSERT INTO Effects VALUES(4,'Take','\take{#}');
INSERT INTO Effects VALUES(5,'See','\see{#}');
INSERT INTO Effects VALUES(6,'Destroy','\destroy{#}');
INSERT INTO Effects VALUES(7,'Speed','\speed{#}');
INSERT INTO Effects VALUES(8,'Move','\move{#}');
INSERT INTO Effects VALUES(10,'Discarded when killed','\discardonkill');
INSERT INTO Effects VALUES(11,'Play when the game starts','\inplayatstart');
INSERT INTO Effects VALUES(12,'Cannot Die','\immortal');
INSERT INTO Effects VALUES(13,'Passing does not incur damage','\safepass');
INSERT INTO Effects VALUES(14,'Dies when passing','\passdie');
INSERT INTO Effects VALUES(15,'Speed Times','\speed{$\times #$}');
INSERT INTO Effects VALUES(16,'Cannot hold attachments','\nohold');
INSERT INTO Effects VALUES(17,'Remove your starvation','\nostarvation');
INSERT INTO Effects VALUES(18,'Remove your hypothermia','\nohypothermia');
INSERT INTO Effects VALUES(19,'Take damage','\damage{#}');
INSERT INTO Effects VALUES(20,'Double the final distance','\doubledistance');
INSERT INTO Effects VALUES(21,'Damage Effect','\damagetext');
INSERT INTO Effects VALUES(22,'Counts as 2 dogs.','\istwodogs');
INSERT INTO Effects VALUES(23,'Your other dogs have +1 speed','\otherdogshave{\speed{1}}');

CREATE TABLE Cards (id INTEGER PRIMARY KEY, Name TEXT, Energy TEXT, Health TEXT, Risk TEXT, Flavour TEXT, Image TEXT, Typename INTEGER REFERENCES Types (id));
INSERT INTO Cards VALUES(1,'A Hat',2,2,0,'I bet its a valve hat.','hat',1);
INSERT INTO Cards VALUES(2,'Dog Chow',1,3,0,'A hungry dog is a slow dog.','dog_chow',1);
INSERT INTO Cards VALUES(3,'Good Dog',3,3,0,'Good boy.','good_dog',2);
INSERT INTO Cards VALUES(4,'Husky',2,2,2,'Standard mushing fare.','husky',2);
INSERT INTO Cards VALUES(5,'Wheel Dog',3,3,0,'The dog right in front of the sled. Strong and steady.','wheel_dog',2);
INSERT INTO Cards VALUES(6,'Breakfast',0,3,0,'The most important meal of the day.','breakfast',3);
INSERT INTO Cards VALUES(7,'Lunch',2,0,0,'What about second breakfast?','lunch',3);
INSERT INTO Cards VALUES(8,'Dinner',2,2,0,'I hope you like salted fish.','dinner',3);
INSERT INTO Cards VALUES(9,'Move',0,0,0,'Just another day.','move',4);
INSERT INTO Cards VALUES(10,'Mush',2,2,1,'Comes from the french word `Marche''.','mush',4);
INSERT INTO Cards VALUES(11,'First Aid',2,2,0,'Reduces swelling.','first_aid',5);
INSERT INTO Cards VALUES(12,'Grandma Soup',1,2,1,'Cures what ails you.','grandma_soup',5);
INSERT INTO Cards VALUES(13,'Repair Sled',1,3,0,'It doesn''t need to be pretty. It just has to work.','repair_sled',6);
INSERT INTO Cards VALUES(14,'Upgrade Sled',2,2,0,'You have to keep your ride in top shape.','upgrade_sled',6);
INSERT INTO Cards VALUES(20,'Buffer Pannel',2,2,0,'Did the primary buffer panel just fall off my gorram ship for no apparent reason?','buffer_panel',1);
INSERT INTO Cards VALUES(21,'Nuclear Reactor',2,2,0,'What could go wrong?','nuclear_reactor',1);
INSERT INTO Cards VALUES(22,'Engineer Dog',3,5,1,'Nails and Gears.','engineer_dog',2);
INSERT INTO Cards VALUES(23,'Moose',5,0,3,'Majestic creatures. Hard to tame.','moose',2);
INSERT INTO Cards VALUES(24,'Waffle',0,0,0,'Waffles are \textbf{delicious}.','waffles',3);
INSERT INTO Cards VALUES(25,'Whale Meat',1,1,0,'It''s like rubber.','whale_meat',3);
INSERT INTO Cards VALUES(26,'Hitch a Ride',1,0,0,'Probably not in the spirit of the race.','hitch_a_ride',4);
INSERT INTO Cards VALUES(27,'Tactical Play',1,0,1,'Make the most of it.','tactical_play',4);
INSERT INTO Cards VALUES(28,'Meditate',1,1,0,'It \textit{is} just sitting.','meditate',5);
INSERT INTO Cards VALUES(29,'Diamorphine',1,1,1,'Highly addicting.','diamorphine',5);
INSERT INTO Cards VALUES(30,'Desperate Times',99,0,0,'Desperate Measures hotline, how may I help you?','desperate_times',6);
INSERT INTO Cards VALUES(31,'Lead Sled',1,1,1,'At least its not a Zeppelin.','lead_sled',6);
INSERT INTO Cards VALUES(40,'Damaged',1,1,0,'You have been hurt.','damaged',8);
INSERT INTO Cards VALUES(100,'Dog Shoes',2,3,0,'Dogs look cute in shoes.','dog_shoes',1);
INSERT INTO Cards VALUES(101,'Squirrel',2,2,1,'Dogs \emph{hate} squirrels.','squirrel',1);
INSERT INTO Cards VALUES(102,'Tiara',2,2,1,'Makes the dog feel special.','tiara',1);
INSERT INTO Cards VALUES(103,'Bear',2,2,2,'In hindsight, not the best idea.','bear',2);
INSERT INTO Cards VALUES(104,'Big Dog',2,2,0,'He''s not red though.','big_dog',2);
INSERT INTO Cards VALUES(105,'Greyhound',0,0,2,'What happens when you mix the colours on a husky? You get a grey hound.','greyhound',2);
INSERT INTO Cards VALUES(106,'Malamute',2,2,1,'A common sled hauling breed.','malamute',2);
INSERT INTO Cards VALUES(107,'Problem Dog',1,1,1,'I swear, if you weren''t so fast.','problem_dog',2);
INSERT INTO Cards VALUES(108,'Bison',2,0,1,'It''s very lean.','bison',3);
INSERT INTO Cards VALUES(109,'Poutine',0,2,0,'The great Canadian carb!','poutine',3);
INSERT INTO Cards VALUES(110,'Venison',0,2,0,'Better than breakfast.','venison',3);
INSERT INTO Cards VALUES(111,'Steak',0,0,0,'Well aren''t you fancy.','steak',3);
INSERT INTO Cards VALUES(112,'Jerky',1,1,0,'Watch your sodium!','jerky',3);
INSERT INTO Cards VALUES(113,'Midnight Sun',1,1,1,'Strange things are done in the midnight sun.','midnight_sun',4);
INSERT INTO Cards VALUES(114,'Push',1,0,0,'Not a full mush, but still putting in some effort.','push',4);
INSERT INTO Cards VALUES(115,'Slow and Steady',0,0,0,'Maybe a bit too slow.','slow_and_steady',4);
INSERT INTO Cards VALUES(116,'Band Aid',0,0,0,'Not much.','band_aid',5);
INSERT INTO Cards VALUES(117,'Bandage',1,0,0,'Make sure you wrap it tight.','bandage',5);
INSERT INTO Cards VALUES(118,'Brandy',0,0,1,'Brought by a St. Bernard.','brandy',5);
INSERT INTO Cards VALUES(119,'Caffeine',0,2,0,'The greatest addiction ever.','caffeine',5);
INSERT INTO Cards VALUES(120,'Improvise',0,0,0,'MacGyver of the north.','improvise',6);
INSERT INTO Cards VALUES(121,'Makeshift Sled',1,1,0,'Rickety, but it''ll hold.','makeshift_sled',6);
INSERT INTO Cards VALUES(122,'Salvage',1,1,0,'Take the good with the bad.','salvage',6);
INSERT INTO Cards VALUES(123,'Antique Sled',0,5,0,'Withstood the test of time.','antique_sled',6);
INSERT INTO Cards VALUES(124,'Rush',0,3,1,'Hurry up!','rush',6);

CREATE TABLE Card_Effects (Card INTEGER REFERENCES Cards (id), Effect INTEGER REFERENCES Effects (id), Amount INTEGER);
INSERT INTO Card_Effects VALUES(1,1,1);
INSERT INTO Card_Effects VALUES(2,7,1);
INSERT INTO Card_Effects VALUES(3,1,1);
INSERT INTO Card_Effects VALUES(4,1,1);
INSERT INTO Card_Effects VALUES(4,7,1);
INSERT INTO Card_Effects VALUES(5,7,1);
INSERT INTO Card_Effects VALUES(5,10,1);
INSERT INTO Card_Effects VALUES(5,11,1);
INSERT INTO Card_Effects VALUES(6,2,3);
INSERT INTO Card_Effects VALUES(7,2,3);
INSERT INTO Card_Effects VALUES(8,2,7);
INSERT INTO Card_Effects VALUES(9,8,1);
INSERT INTO Card_Effects VALUES(10,8,10);
INSERT INTO Card_Effects VALUES(11,5,3);
INSERT INTO Card_Effects VALUES(11,6,1);
INSERT INTO Card_Effects VALUES(12,5,10);
INSERT INTO Card_Effects VALUES(12,6,2);
INSERT INTO Card_Effects VALUES(13,3,1);
INSERT INTO Card_Effects VALUES(13,4,2);
INSERT INTO Card_Effects VALUES(14,3,3);
INSERT INTO Card_Effects VALUES(14,4,1);
INSERT INTO Card_Effects VALUES(20,12,1);
INSERT INTO Card_Effects VALUES(20,13,1);
INSERT INTO Card_Effects VALUES(21,7,5);
INSERT INTO Card_Effects VALUES(21,14,1);
INSERT INTO Card_Effects VALUES(22,15,2);
INSERT INTO Card_Effects VALUES(22,16,1);
INSERT INTO Card_Effects VALUES(23,7,5);
INSERT INTO Card_Effects VALUES(23,12,1);
INSERT INTO Card_Effects VALUES(24,2,2);
INSERT INTO Card_Effects VALUES(25,2,5);
INSERT INTO Card_Effects VALUES(25,18,1);
INSERT INTO Card_Effects VALUES(26,8,6);
INSERT INTO Card_Effects VALUES(26,19,1);
INSERT INTO Card_Effects VALUES(27,8,0);
INSERT INTO Card_Effects VALUES(27,20,1);
INSERT INTO Card_Effects VALUES(28,5,99);
INSERT INTO Card_Effects VALUES(28,6,0);
INSERT INTO Card_Effects VALUES(29,5,99);
INSERT INTO Card_Effects VALUES(29,6,99);
INSERT INTO Card_Effects VALUES(30,3,10);
INSERT INTO Card_Effects VALUES(30,4,5);
INSERT INTO Card_Effects VALUES(31,3,10);
INSERT INTO Card_Effects VALUES(31,4,10);
INSERT INTO Card_Effects VALUES(40,21,1);
INSERT INTO Card_Effects VALUES(100,7,2);
INSERT INTO Card_Effects VALUES(101,7,3);
INSERT INTO Card_Effects VALUES(102,7,1);
INSERT INTO Card_Effects VALUES(102,1,1);
INSERT INTO Card_Effects VALUES(103,7,5);
INSERT INTO Card_Effects VALUES(104,7,3);
INSERT INTO Card_Effects VALUES(105,7,3);
INSERT INTO Card_Effects VALUES(105,16,1);
INSERT INTO Card_Effects VALUES(106,1,2);
INSERT INTO Card_Effects VALUES(107,7,3);
INSERT INTO Card_Effects VALUES(107,1,-1);
INSERT INTO Card_Effects VALUES(108,2,5);
INSERT INTO Card_Effects VALUES(109,2,1);
INSERT INTO Card_Effects VALUES(109,18,1);
INSERT INTO Card_Effects VALUES(110,2,3);
INSERT INTO Card_Effects VALUES(111,2,1);
INSERT INTO Card_Effects VALUES(112,2,3);
INSERT INTO Card_Effects VALUES(113,8,10);
INSERT INTO Card_Effects VALUES(114,8,5);
INSERT INTO Card_Effects VALUES(115,8,0);
INSERT INTO Card_Effects VALUES(115,2,1);
INSERT INTO Card_Effects VALUES(116,5,1);
INSERT INTO Card_Effects VALUES(116,6,1);
INSERT INTO Card_Effects VALUES(117,5,1);
INSERT INTO Card_Effects VALUES(117,6,5);
INSERT INTO Card_Effects VALUES(118,5,1);
INSERT INTO Card_Effects VALUES(118,6,5);
INSERT INTO Card_Effects VALUES(119,5,1);
INSERT INTO Card_Effects VALUES(119,6,2);
INSERT INTO Card_Effects VALUES(119,2,1);
INSERT INTO Card_Effects VALUES(120,4,1);
INSERT INTO Card_Effects VALUES(121,3,2);
INSERT INTO Card_Effects VALUES(121,4,6);
INSERT INTO Card_Effects VALUES(122,3,3);
INSERT INTO Card_Effects VALUES(122,4,2);
INSERT INTO Card_Effects VALUES(123,3,2);
INSERT INTO Card_Effects VALUES(123,4,8);

CREATE TABLE Deck_Cards (Deck INTEGER REFERENCES Decks (id), Card INTEGER REFERENCES Cards (id), Amount INTEGER);
INSERT INTO Deck_Cards VALUES(1,1,1);
INSERT INTO Deck_Cards VALUES(2,1,1);
INSERT INTO Deck_Cards VALUES(3,1,1);
INSERT INTO Deck_Cards VALUES(4,1,1);
INSERT INTO Deck_Cards VALUES(1,2,1);
INSERT INTO Deck_Cards VALUES(2,2,1);
INSERT INTO Deck_Cards VALUES(3,2,1);
INSERT INTO Deck_Cards VALUES(4,2,1);
INSERT INTO Deck_Cards VALUES(1,3,1);
INSERT INTO Deck_Cards VALUES(2,3,1);
INSERT INTO Deck_Cards VALUES(3,3,1);
INSERT INTO Deck_Cards VALUES(4,3,1);
INSERT INTO Deck_Cards VALUES(1,4,1);
INSERT INTO Deck_Cards VALUES(2,4,1);
INSERT INTO Deck_Cards VALUES(3,4,1);
INSERT INTO Deck_Cards VALUES(4,4,1);
INSERT INTO Deck_Cards VALUES(1,5,1);
INSERT INTO Deck_Cards VALUES(2,5,1);
INSERT INTO Deck_Cards VALUES(3,5,1);
INSERT INTO Deck_Cards VALUES(4,5,1);
INSERT INTO Deck_Cards VALUES(1,6,2);
INSERT INTO Deck_Cards VALUES(2,6,2);
INSERT INTO Deck_Cards VALUES(3,6,2);
INSERT INTO Deck_Cards VALUES(4,6,2);
INSERT INTO Deck_Cards VALUES(1,7,2);
INSERT INTO Deck_Cards VALUES(2,7,2);
INSERT INTO Deck_Cards VALUES(3,7,2);
INSERT INTO Deck_Cards VALUES(4,7,2);
INSERT INTO Deck_Cards VALUES(1,8,1);
INSERT INTO Deck_Cards VALUES(2,8,1);
INSERT INTO Deck_Cards VALUES(3,8,1);
INSERT INTO Deck_Cards VALUES(4,8,1);
INSERT INTO Deck_Cards VALUES(1,9,4);
INSERT INTO Deck_Cards VALUES(2,9,4);
INSERT INTO Deck_Cards VALUES(3,9,4);
INSERT INTO Deck_Cards VALUES(4,9,4);
INSERT INTO Deck_Cards VALUES(1,10,1);
INSERT INTO Deck_Cards VALUES(2,10,1);
INSERT INTO Deck_Cards VALUES(3,10,1);
INSERT INTO Deck_Cards VALUES(4,10,1);
INSERT INTO Deck_Cards VALUES(1,11,2);
INSERT INTO Deck_Cards VALUES(2,11,2);
INSERT INTO Deck_Cards VALUES(3,11,2);
INSERT INTO Deck_Cards VALUES(4,11,2);
INSERT INTO Deck_Cards VALUES(1,12,1);
INSERT INTO Deck_Cards VALUES(2,12,1);
INSERT INTO Deck_Cards VALUES(3,12,1);
INSERT INTO Deck_Cards VALUES(4,12,1);
INSERT INTO Deck_Cards VALUES(1,13,2);
INSERT INTO Deck_Cards VALUES(2,13,2);
INSERT INTO Deck_Cards VALUES(3,13,2);
INSERT INTO Deck_Cards VALUES(4,13,2);
INSERT INTO Deck_Cards VALUES(1,14,2);
INSERT INTO Deck_Cards VALUES(2,14,2);
INSERT INTO Deck_Cards VALUES(3,14,2);
INSERT INTO Deck_Cards VALUES(4,14,2);
INSERT INTO Deck_Cards VALUES(20,20,1);
INSERT INTO Deck_Cards VALUES(20,21,1);
INSERT INTO Deck_Cards VALUES(20,22,1);
INSERT INTO Deck_Cards VALUES(20,23,1);
INSERT INTO Deck_Cards VALUES(20,24,1);
INSERT INTO Deck_Cards VALUES(20,25,1);
INSERT INTO Deck_Cards VALUES(20,26,1);
INSERT INTO Deck_Cards VALUES(20,27,1);
INSERT INTO Deck_Cards VALUES(20,28,1);
INSERT INTO Deck_Cards VALUES(20,29,1);
INSERT INTO Deck_Cards VALUES(20,30,1);
INSERT INTO Deck_Cards VALUES(20,31,1);
INSERT INTO Deck_Cards VALUES(21,40,26);

INSERT INTO Deck_Cards VALUES(10,106,2);
INSERT INTO Deck_Cards VALUES(10,108,2);
INSERT INTO Deck_Cards VALUES(10,109,2);
INSERT INTO Deck_Cards VALUES(10,110,2);
INSERT INTO Deck_Cards VALUES(10,111,2);
INSERT INTO Deck_Cards VALUES(10,112,2);
INSERT INTO Deck_Cards VALUES(10,116,2);
INSERT INTO Deck_Cards VALUES(10,117,2);
INSERT INTO Deck_Cards VALUES(10,118,2);
INSERT INTO Deck_Cards VALUES(10,119,2);
INSERT INTO Deck_Cards VALUES(11,120,2);
INSERT INTO Deck_Cards VALUES(10,121,2);
INSERT INTO Deck_Cards VALUES(10,122,2);
INSERT INTO Deck_Cards VALUES(10,123,2);

INSERT INTO Deck_Cards VALUES(11,100,2);
INSERT INTO Deck_Cards VALUES(11,101,2);
INSERT INTO Deck_Cards VALUES(11,102,2);
INSERT INTO Deck_Cards VALUES(11,103,2);
INSERT INTO Deck_Cards VALUES(11,104,2);
INSERT INTO Deck_Cards VALUES(11,105,2);
INSERT INTO Deck_Cards VALUES(11,107,2);
INSERT INTO Deck_Cards VALUES(11,113,2);
INSERT INTO Deck_Cards VALUES(11,114,2);
INSERT INTO Deck_Cards VALUES(11,115,2);
-- 2 more movements (or 1 movement, 1 dog)


CREATE VIEW Card_List AS
SELECT
    Cards.Name AS 'Card Name',
    Cards.Energy AS 'Energy Cost',
    Cards.Health AS 'Health Cost',
    Cards.Risk AS 'Risk',
    Cards.Flavour AS 'Flavour',
    Cards.Image AS 'Image',
    Types.Name AS 'Type',
    group_concat(replace(Effects.Command,'#',Card_Effects.Amount), '\\') AS 'Effect(s)',
    Decks.Name AS 'In Deck',
    Deck_Cards.Amount AS 'Count'
FROM Cards
    JOIN Types ON Types.id = Cards.Typename
    CROSS JOIN Card_Effects ON Card_Effects.Card = Cards.id
    JOIN Effects ON Effects.id = Card_Effects.Effect
    CROSS JOIN Deck_Cards ON Deck_Cards.Card = Cards.id
    JOIN Decks ON Deck_Cards.Deck = Decks.id
GROUP BY
    Cards.id,
    Decks.id
ORDER BY Cards.Name;
COMMIT;
