-- V55: P4 도메인에서 사용하는 공통코드 그룹/상세 일괄 INSERT
-- core-architect 가 사용한 코드 그룹 누락분 보강.

-- group_code 길이 한도 상향 (기존 VARCHAR(20) → 30) — NOTIFICATION_REF_TYPE / AGENT_CONTRACT_STATUS 등 21자 이상 수용
ALTER TABLE common_code_group ALTER COLUMN group_code TYPE VARCHAR(30);
ALTER TABLE common_code       ALTER COLUMN group_code TYPE VARCHAR(30);

-- ===== 그룹 =====
INSERT INTO common_code_group (group_code, group_name, description, is_system, sort_order) VALUES
 ('PAYMENT_CYCLE',        '수금주기',           'MONTHLY/QUARTERLY/SEMI/ANNUAL',          'Y', 200),
 ('BONUS_TYPE',           '수당지급유형',        'RATE/FIXED',                            'Y', 210),
 ('RETENTION_MONTH',      '유지기준개월',        'M13/M25/M37/M49',                       'Y', 220),
 ('AGENT_CONTRACT_STATUS','위촉계약상태',        'ACTIVE/TERMINATED',                     'Y', 230),
 ('LICENSE_TYPE',         '자격증유형',          'LIFE/NONLIFE/VARIABLE',                 'Y', 240),
 ('LICENSE_STATUS',       '자격증상태',          'ACTIVE/EXPIRED/SUSPENDED',              'Y', 250),
 ('COURSE_TYPE',          '교육유형',            'REGULAR/COMPLIANCE/PRODUCT',            'Y', 260),
 ('ENDORSEMENT_TYPE',     '계약변경유형',        'PREMIUM/BENEFICIARY/INSURED/ADDRESS',   'Y', 270),
 ('COMPLAINT_CHANNEL',    '민원접수채널',        'PHONE/EMAIL/VISIT/ONLINE',              'Y', 280),
 ('COMPLAINT_TYPE',       '민원유형',            'MIS_SELLING/DELAY/COVERAGE/REFUND/ETC', 'Y', 290),
 ('COMPLAINT_SEVERITY',   '민원심각도',          'LOW/MID/HIGH',                          'Y', 300),
 ('COMPLAINT_STATUS',     '민원처리상태',        'OPEN/IN_PROGRESS/CLOSED',               'Y', 310),
 ('APPROVAL_STATUS',      '결재상태',            'PENDING/APPROVED/REJECTED/CANCEL',      'Y', 320),
 ('APPROVAL_ACTION',      '결재처리',            'APPROVE/REJECT',                        'Y', 330),
 ('NOTICE_TYPE',          '공지유형',            'SYSTEM/POLICY/EVENT',                   'Y', 340),
 ('NOTIFICATION_REF_TYPE','알림참조유형',        'SETTLE/DISPUTE/INCENTIVE/WITHDRAW/...', 'Y', 350),
 ('ATTACHMENT_REF_TYPE',  '첨부참조유형',        'AGENT_CONTRACT/COMPLAINT/...',          'Y', 360),
 ('WITHDRAW_STATUS',      '출금신청상태',        'REQUESTED/APPROVED/SENT/COMPLETED/FAILED','Y', 370),
 ('HOLD_REASON',          '보류사유',            'NEED_DOC/UNDER_REVIEW/DISPUTE_OPEN/...','Y', 380)
ON CONFLICT (group_code) DO NOTHING;

-- ===== 상세 =====
INSERT INTO common_code (group_code, code, code_name, sort_order) VALUES
 -- PAYMENT_CYCLE
 ('PAYMENT_CYCLE','MONTHLY','월납',10),
 ('PAYMENT_CYCLE','QUARTERLY','분기납',20),
 ('PAYMENT_CYCLE','SEMI','반기납',30),
 ('PAYMENT_CYCLE','ANNUAL','연납',40),
 -- BONUS_TYPE
 ('BONUS_TYPE','RATE','정률',10),
 ('BONUS_TYPE','FIXED','정액',20),
 -- RETENTION_MONTH
 ('RETENTION_MONTH','M13','13개월',10),
 ('RETENTION_MONTH','M25','25개월',20),
 ('RETENTION_MONTH','M37','37개월',30),
 ('RETENTION_MONTH','M49','49개월',40),
 -- AGENT_CONTRACT_STATUS
 ('AGENT_CONTRACT_STATUS','ACTIVE','유효',10),
 ('AGENT_CONTRACT_STATUS','TERMINATED','해촉',20),
 -- LICENSE_TYPE
 ('LICENSE_TYPE','LIFE','생명보험',10),
 ('LICENSE_TYPE','NONLIFE','손해보험',20),
 ('LICENSE_TYPE','VARIABLE','변액보험',30),
 -- LICENSE_STATUS
 ('LICENSE_STATUS','ACTIVE','유효',10),
 ('LICENSE_STATUS','EXPIRED','만료',20),
 ('LICENSE_STATUS','SUSPENDED','정지',30),
 -- COURSE_TYPE
 ('COURSE_TYPE','REGULAR','보수교육',10),
 ('COURSE_TYPE','COMPLIANCE','준법교육',20),
 ('COURSE_TYPE','PRODUCT','상품교육',30),
 -- ENDORSEMENT_TYPE
 ('ENDORSEMENT_TYPE','PREMIUM_CHANGE','보험료변경',10),
 ('ENDORSEMENT_TYPE','BENEFICIARY','수익자변경',20),
 ('ENDORSEMENT_TYPE','INSURED','피보험자변경',30),
 ('ENDORSEMENT_TYPE','ADDRESS','주소변경',40),
 -- COMPLAINT_CHANNEL
 ('COMPLAINT_CHANNEL','PHONE','전화',10),
 ('COMPLAINT_CHANNEL','EMAIL','이메일',20),
 ('COMPLAINT_CHANNEL','VISIT','방문',30),
 ('COMPLAINT_CHANNEL','ONLINE','온라인',40),
 -- COMPLAINT_TYPE
 ('COMPLAINT_TYPE','MIS_SELLING','불완전판매',10),
 ('COMPLAINT_TYPE','DELAY','업무지연',20),
 ('COMPLAINT_TYPE','COVERAGE','보장설명미흡',30),
 ('COMPLAINT_TYPE','REFUND','환급요청',40),
 ('COMPLAINT_TYPE','ETC','기타',90),
 -- COMPLAINT_SEVERITY
 ('COMPLAINT_SEVERITY','LOW','경미',10),
 ('COMPLAINT_SEVERITY','MID','보통',20),
 ('COMPLAINT_SEVERITY','HIGH','중대',30),
 -- COMPLAINT_STATUS
 ('COMPLAINT_STATUS','OPEN','접수',10),
 ('COMPLAINT_STATUS','IN_PROGRESS','처리중',20),
 ('COMPLAINT_STATUS','CLOSED','처리완료',30),
 -- APPROVAL_STATUS
 ('APPROVAL_STATUS','PENDING','결재대기',10),
 ('APPROVAL_STATUS','APPROVED','승인',20),
 ('APPROVAL_STATUS','REJECTED','반려',30),
 ('APPROVAL_STATUS','CANCEL','취소',40),
 -- APPROVAL_ACTION
 ('APPROVAL_ACTION','APPROVE','승인',10),
 ('APPROVAL_ACTION','REJECT','반려',20),
 -- NOTICE_TYPE
 ('NOTICE_TYPE','SYSTEM','시스템',10),
 ('NOTICE_TYPE','POLICY','정책',20),
 ('NOTICE_TYPE','EVENT','이벤트',30),
 -- NOTIFICATION_REF_TYPE
 ('NOTIFICATION_REF_TYPE','SETTLE','정산',10),
 ('NOTIFICATION_REF_TYPE','DISPUTE','이의신청',20),
 ('NOTIFICATION_REF_TYPE','INCENTIVE','시책',30),
 ('NOTIFICATION_REF_TYPE','WITHDRAW','출금',40),
 ('NOTIFICATION_REF_TYPE','COMPLAINT','민원',50),
 ('NOTIFICATION_REF_TYPE','APPROVAL','결재',60),
 ('NOTIFICATION_REF_TYPE','SYSTEM','시스템',70),
 -- ATTACHMENT_REF_TYPE
 ('ATTACHMENT_REF_TYPE','AGENT_CONTRACT','위촉계약서',10),
 ('ATTACHMENT_REF_TYPE','COMPLAINT','민원',20),
 ('ATTACHMENT_REF_TYPE','DISPUTE','이의신청',30),
 ('ATTACHMENT_REF_TYPE','SETTLE','정산',40),
 ('ATTACHMENT_REF_TYPE','TRAINING','교육',50),
 ('ATTACHMENT_REF_TYPE','LICENSE','자격증',60),
 ('ATTACHMENT_REF_TYPE','ENDORSEMENT','계약변경',70),
 ('ATTACHMENT_REF_TYPE','NOTICE','공지',80),
 ('ATTACHMENT_REF_TYPE','ETC','기타',90),
 -- WITHDRAW_STATUS
 ('WITHDRAW_STATUS','REQUESTED','신청',10),
 ('WITHDRAW_STATUS','APPROVED','승인',20),
 ('WITHDRAW_STATUS','SENT','전송완료',30),
 ('WITHDRAW_STATUS','COMPLETED','이체완료',40),
 ('WITHDRAW_STATUS','FAILED','실패',90),
 -- HOLD_REASON
 ('HOLD_REASON','NEED_DOC','서류미비',10),
 ('HOLD_REASON','UNDER_REVIEW','검토중',20),
 ('HOLD_REASON','DISPUTE_OPEN','이의신청중',30),
 ('HOLD_REASON','LICENSE_EXPIRED','자격증만료',40),
 ('HOLD_REASON','TRAINING_INSUFFICIENT','교육시간미달',50),
 ('HOLD_REASON','ETC','기타',90)
ON CONFLICT (group_code, code) DO NOTHING;
