-- V105: incar 갭 운영 도메인 공통코드 6종 (V96 패턴 동일)
--       STEP_CODE / STEP_STATUS / HQ_ITEM_TYPE / JOINT_ROLE / GUARANTEE_STATUS / GRADE_EVAL_STATUS

-- ===== 그룹 =====
INSERT INTO common_code_group (group_code, group_name, description, is_system, sort_order) VALUES
 ('STEP_CODE',         '단계코드',       'RECEIVE=수신마감/CALC=계산마감/VERIFY=검증마감/PAY=지급마감', 'Y', 490),
 ('STEP_STATUS',       '단계상태',       'OPEN=열림/CLOSED=마감',                                      'Y', 500),
 ('HQ_ITEM_TYPE',      '본사정산유형',   'INCOME=수입/EXPENSE=비용',                                   'Y', 510),
 ('JOINT_ROLE',        '공동계약역할',   'LEAD=주설계사/SUB=공동설계사',                               'Y', 520),
 ('GUARANTEE_STATUS',  '보증보험상태',   'ACTIVE=유효/EXPIRED=만료/CANCELLED=해지',                   'Y', 530),
 ('GRADE_EVAL_STATUS', '등급평가상태',   'EVALUATED=평가완료/APPLIED=반영완료',                        'Y', 540)
ON CONFLICT (group_code) DO NOTHING;

-- ===== 상세 =====
INSERT INTO common_code (group_code, code, code_name, sort_order) VALUES
 -- STEP_CODE
 ('STEP_CODE', 'RECEIVE', '수신마감', 10),
 ('STEP_CODE', 'CALC',    '계산마감', 20),
 ('STEP_CODE', 'VERIFY',  '검증마감', 30),
 ('STEP_CODE', 'PAY',     '지급마감', 40),
 -- STEP_STATUS
 ('STEP_STATUS', 'OPEN',   '열림', 10),
 ('STEP_STATUS', 'CLOSED', '마감', 20),
 -- HQ_ITEM_TYPE
 ('HQ_ITEM_TYPE', 'INCOME',  '수입', 10),
 ('HQ_ITEM_TYPE', 'EXPENSE', '비용', 20),
 -- JOINT_ROLE
 ('JOINT_ROLE', 'LEAD', '주설계사',  10),
 ('JOINT_ROLE', 'SUB',  '공동설계사', 20),
 -- GUARANTEE_STATUS
 ('GUARANTEE_STATUS', 'ACTIVE',    '유효', 10),
 ('GUARANTEE_STATUS', 'EXPIRED',   '만료', 20),
 ('GUARANTEE_STATUS', 'CANCELLED', '해지', 30),
 -- GRADE_EVAL_STATUS
 ('GRADE_EVAL_STATUS', 'EVALUATED', '평가완료', 10),
 ('GRADE_EVAL_STATUS', 'APPLIED',   '반영완료', 20)
ON CONFLICT (group_code, code) DO NOTHING;
