-- Carboany Simulation Seed v1.2: Full Value Chain Cycle
-- Pillars: CPM (Jeju Gov), SME (EcoTech), FIN (GreenFinance), APP (Participants), PLT (Platform)

-- 1. Organizations Setup
INSERT INTO public.organizations (id, name, type, business_reg_number, contact_email)
VALUES
  ('cpm-jeju-001', '제주특별자치도청', 'municipality', '123-45-67890', 'env@jeju.go.kr'),
  ('sme-ecotech-001', '(주)에코테크', 'sme', '222-33-44444', 'ceo@ecotech.com'),
  ('fin-green-001', '그린인베스트먼트', 'enterprise', '999-88-77777', 'trade@greeninv.com')
ON CONFLICT (id) DO NOTHING;

-- 2. Budget Deposit (Primary Capital)
-- CPM -> SYSTEM_ESCROW (50,000,000 KRW)
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, hash, status)
VALUES
  ('tx-budget-001', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', 'cpm-jeju-001', '제주특별자치도청', 'SYSTEM_ESCROW', '시스템 예산 풀', 'BUDGET_DEPOSIT', 'KRW', 50000000, '제주 텀블러 챌린지 2026 운영 예산 입금', 'initial_hash_placeholder', 'completed');

-- 3. Primary Distribution (1st Payout: Budget -> Participants)
-- PLT Fee (10%)
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES
  ('tx-fee-p1-001', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', 'SYSTEM_ESCROW', '캠페인 예산 풀', 'PLATFORM_OPERATIONS', '플랫폼 운영 수익', 'FEE_DEDUCTION', 'KRW', 5000000, '운영 대행 수수료 (10%)', 'completed');

-- Citizen Reward (Example for 1st participant)
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES
  ('tx-dist-p1-001', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', 'SYSTEM_ESCROW', '캠페인 예산 풀', 'demo-user-id', '홍길동(시민)', 'POINT_REWARD', 'POINT', 15000, '1차 활동 인증 보상 (감축 기여)', 'completed');

-- 4. Credit Issuance & SME Donation (Secondary Path A: Registry -> SME)
-- Issued 100 TON from the campaign
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES
  ('tx-credit-issue-001', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', 'ORS_REGISTRY', '환경부 레지스트리', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', '캠페인 자산 풀', 'CREDIT_ISSUANCE', 'TON', 100.0, '제주 텀블러 프로젝트 배출권 발행 승인', 'completed');

-- Donate 10 TON to SME
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES
  ('tx-sme-don-001', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', '캠페인 자산 풀', 'sme-ecotech-001', '(주)에코테크', 'CREDIT_DONATION', 'TON', 10.0, '수출 기업 탄소 중립 기여 기부 (상생)', 'completed');

-- 5. Credit Sale & Secondary Distribution (Secondary Path B: Sale -> FIN -> Participants)
-- FIN buys 50 TON @ 15,000 KRW = 750,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
  ('tx-sale-001', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', 'fin-green-001', '그린인베스트먼트', 'FIN_PAYMENT_ESCROW', '매각 대금 풀', 'BUDGET_DEPOSIT', 'KRW', 750000, '탄소배출권 50t 매입 대금 결제', 'completed');

-- PLT Fee (5%) + Verification Cost (50,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
  ('tx-fee-p2-001', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', 'FIN_PAYMENT_ESCROW', '매각 대금 풀', 'PLATFORM_FINANCE', '금융 중개 수수료', 'FEE_DEDUCTION', 'KRW', 37500, '배출권 거래 수수료 (5%)', 'completed'),
  ('tx-verif-001', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', 'FIN_PAYMENT_ESCROW', '매각 대금 풀', 'VERIFICATION_ENTITY', '외부 검증 기관', 'FEE_DEDUCTION', 'KRW', 50000, '외부 검증(VCS) 대행 비용', 'completed');

-- Dividend to Citizen (2nd Payout)
INSERT INTO public.settlement_ledger (transaction_id, campaign_id, sender_id, sender_name, receiver_id, receiver_name, category, asset, amount, description, status)
VALUES
  ('tx-dist-p2-001', '47e3d9aa-8bc0-423c-9d5d-4e9a093eb5eb', 'FIN_PAYMENT_ESCROW', '매각 대금 풀', 'demo-user-id', '홍길동(시민)', 'FINANCE_DIVIDEND', 'POINT', 10000, '배출권 매각 추가 수익 분배', 'completed');
