-- Carboany Wando County Full Lifecycle Simulation (v1.2)

-- 1. Organizations: The 5 Pillars of Wando
INSERT INTO public.organizations (id, name, type, business_reg_number, contact_email)
VALUES
  ('wando-gov', '전라남도 완도군청', 'municipality', '631-83-00001', 'env@wando.go.kr'),
  ('wando-eco-factory', '(주)완도에코자재', 'sme', '222-33-00001', 'ceo@wandoeco.com'),
  ('global-carbon-fund', '글로벌 탄소 투자조합', 'enterprise', '999-88-00001', 'invest@globalcarbon.com')
ON CONFLICT (id) DO NOTHING;

-- 2. Campaigns Setup
-- 바다 연금 모델 (Model 001)
INSERT INTO public.campaigns (id, sponsor_id, title, description, region, status, target_co2_kg, target_participants, start_date)
VALUES ('wando-ocean-pension', 'wando-gov', '[바다연금] 완도 해조류 블루카본 프로젝트', '완도 전역 해조류 양식장의 탄소 흡수량을 자산화하여 전 군민에게 배분', '전남 완도군', 'active', 6789000000, 50000, '2026-05-01')
ON CONFLICT (id) DO NOTHING;

-- 3. Primary Distribution Simulation (Budget Deposit & Activity Rewards)
-- CPM -> SYSTEM_ESCROW (200,000,000 KRW Deposit)
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES ('wando-tx-001', 'wando-ocean-pension', 'wando-gov', '완도군청', 'SYSTEM_ESCROW', '완도군 운영 예산 풀', 'BUDGET_DEPOSIT', 'KRW', 200000000, '완도 바다연금 캠페인 초기 운영 예산', 'completed');

-- 1st Payout: 10% Fee to Platform
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES ('wando-fee-001', 'wando-ocean-pension', 'SYSTEM_ESCROW', '완도군 운영 예산 풀', 'PLATFORM_OPERATIONS', 'Carboany 플랫폼', 'FEE_DEDUCTION', 'KRW', 20000000, '운영 대행 수수료 (10%)', 'completed');

-- 4. Secondary Value Flow: Credit Issuance & SME Donation
-- Issuing Blue Carbon Credits (Initial 10,000 Ton)
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES ('wando-asset-001', 'wando-ocean-pension', 'ORS_REGISTRY', '환경부 ORS', 'wando-ocean-pension', '완도 블루카본 자산 풀', 'CREDIT_ISSUANCE', 'TON', 10000.0, '2026년 1차 해조류 탄소 흡수분 발행 승인', 'completed');

-- Donate 1,500 Ton (15%) to Local SME (Eco Factory)
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES ('wando-sme-don-001', 'wando-ocean-pension', 'wando-ocean-pension', '완도 블루카본 자산 풀', 'wando-eco-factory', '(주)완도에코자재', 'CREDIT_DONATION', 'TON', 1500.0, '지역 중소기업 수출 경쟁력 지원 (상생 기부)', 'completed');

-- 5. Finance Trade: Selling 5,000 Ton to Global Fund
-- FIN buys 5,000 Ton @ 20,000 KRW = 100,000,000 KRW
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES ('wando-trade-001', 'wando-ocean-pension', 'global-carbon-fund', '글로벌 탄소 투자조합', 'FIN_PAYMENT_ESCROW', '완도 매각 대금 풀', 'BUDGET_DEPOSIT', 'KRW', 100000000, '완도 블루 크레딧 5,000t 매입 결제', 'completed');

-- 2nd Payout: Share 75% of profit to Citizens (Example user)
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES ('wando-div-001', 'wando-ocean-pension', 'FIN_PAYMENT_ESCROW', '완도 매각 대금 풀', 'demo-user-id', '완도군민A', 'FINANCE_DIVIDEND', 'POINT', 50000, '블루 크레딧 매각 수익 공유 (바다 연금)', 'completed');
