-- Give extra moon bucks

UPDATE bank_account SET balance = 100 WHERE user_id = 1;
SELECT * FROM bank_account WHERE user_id = 1;

--
SELECT staking_event.id,well_id,staking_event.source_id,
    inventory_item_id,staking_event.created_at,expiration_at
FROM staking_event
INNER JOIN resource_well ON resource_well.id = well_id
INNER JOIN staking_source on staking_event.source_id = staking_source.id
WHERE staking_event.source_id = ? AND staking_source.user_id = ?;

SELECT name,init_supply
FROM resource_well
INNER JOIN resource ON resource.id = resource_well.resource_id
WHERE source_id = 1;

SELECT inventory_item.id,store_item_id, COUNT(upgrade_event.id) as upgrades
FROM inventory_item
LEFT JOIN upgrade_event ON inventory_item.id = upgrade_event.inventory_item_id
WHERE inventory_item.user_id = 1
GROUP BY inventory_item.id;

SELECT inventory_item.id,store_item_id
FROM inventory_item;

SELECT staking_event.id,well_id,staking_event.source_id,
    inventory_item_id,staking_event.created_at,expiration_at
FROM staking_event
INNER JOIN staking_source on staking_event.source_id = staking_source.id
WHERE staking_event.source_id = 4 AND staking_source.user_id = 1;

SELECT staking_event.id, staking_event.well_id, staking_event.source_id,
    staking_event.inventory_item_id, staking_event.duration_in_mins,
    staking_event.created_at
FROM staking_event
LEFT JOIN claim_event ON staking_event.id = claim_event.staking_event_id
WHERE staking_event.source_id = 4 AND claim_event.staking_event_id IS NULL;

UPDATE staking_event SET created_at = '2023-03-16 09:39:37' WHERE id = 3;

SELECT staking_event.id, staking_source.id as sourceId, resname as resourceType,
    inventory_item_id, duration_in_mins, stake_amount, staking_event.created_at,
    CASE WHEN claim_event.staking_event_id IS NULL THEN 1 ELSE 0 END AS unclaimed
FROM staking_event
INNER JOIN resource_well ON well_id = resource_well.id
INNER JOIN staking_source ON source_id = staking_source.id
LEFT JOIN claim_event ON staking_event.id = claim_event.staking_event_id
WHERE staking_event.user_id = 1;

SELECT resource_account.id, resource_id,resource.name,balance
FROM resource_account
INNER JOIN resource ON resource_id = resource.id
WHERE user_id = 1;

SELECT staking_source.id as sourceId,resource_well.id as wellId,resname,supply FROM resource_well
INNER JOIN staking_source ON staking_source.id = resource_well.source_id
WHERE staking_source.user_id = 1;

SELECT inventory_item.id, tier, store_item_id,
    CASE WHEN claim_event.staking_event_id IS NULL THEN 0 ELSE 1 END AS staking
FROM inventory_item
LEFT JOIN staking_event ON inventory_item_id = inventory_item.id
LEFT JOIN claim_event ON staking_event.id = claim_event.staking_event_id
WHERE inventory_item.id = 3;

SELECT inventory_item.id, tier, store_item_id, staking_event.id as stakeId,
      staking_event.created_at as stakeTime, duration_in_mins, stake_amount
FROM inventory_item
LEFT JOIN staking_event ON inventory_item_id = inventory_item.id
WHERE inventory_item.store_item_id = 'item3' AND user_id = 1
ORDER BY staking_event.created_at DESC;
