-- 템플릿 관련 테이블 생성 SQL
-- MySQL 5.0 호환 (ENGINE=MyISAM)

-- 1. 템플릿 로그 테이블
CREATE TABLE IF NOT EXISTS iw_template_log (
    log_no INT AUTO_INCREMENT PRIMARY KEY,
    log_type VARCHAR(20),
    template_ep_code VARCHAR(50),
    target_ep_code VARCHAR(50),
    mb_code VARCHAR(50),
    mb_name VARCHAR(100),
    mb_mail VARCHAR(100),
    log_action VARCHAR(200),
    log_options TEXT,
    log_id_mapping TEXT,
    log_status VARCHAR(20),
    log_ip VARCHAR(45),
    log_user_agent TEXT,
    log_datetime DATETIME,
    INDEX idx_template (template_ep_code),
    INDEX idx_target (target_ep_code)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- 2. 템플릿 카테고리 테이블
CREATE TABLE IF NOT EXISTS iw_template_category (
    tc_code VARCHAR(20) PRIMARY KEY,
    tc_name VARCHAR(100),
    tc_icon VARCHAR(50),
    tc_order INT DEFAULT 0,
    tc_active TINYINT DEFAULT 1
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- 샘플 카테고리 데이터
INSERT IGNORE INTO iw_template_category (tc_code, tc_name, tc_icon, tc_order, tc_active) VALUES
('basic', '기본형', 'fa fa-square', 1, 1),
('business', '비즈니스', 'fa fa-briefcase', 2, 1),
('shop', '쇼핑몰', 'fa fa-shopping-cart', 3, 1),
('portfolio', '포트폴리오', 'fa fa-images', 4, 1),
('blog', '블로그', 'fa fa-blog', 5, 1),
('custom', '커스텀', 'fa fa-cogs', 6, 1);

-- 3. 홈 메뉴 테이블 (없으면 생성)
CREATE TABLE IF NOT EXISTS iw_home_menu (
    menu_no INT AUTO_INCREMENT PRIMARY KEY,
    ep_code VARCHAR(50),
    gp_code VARCHAR(50),
    menu_name VARCHAR(100),
    menu_link VARCHAR(255),
    menu_target VARCHAR(20) DEFAULT '_self',
    menu_order INT DEFAULT 0,
    menu_use TINYINT DEFAULT 1,
    reg_date DATETIME,
    INDEX idx_ep (ep_code),
    INDEX idx_gp (gp_code)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- 4. 홈 스크랩/섹션 테이블 (없으면 생성)
CREATE TABLE IF NOT EXISTS iw_home_scrap (
    scrap_no INT AUTO_INCREMENT PRIMARY KEY,
    ep_code VARCHAR(50),
    gp_code VARCHAR(50),
    scrap_title VARCHAR(200),
    scrap_content TEXT,
    scrap_type VARCHAR(50),
    scrap_order INT DEFAULT 0,
    scrap_use TINYINT DEFAULT 1,
    reg_date DATETIME,
    INDEX idx_ep (ep_code),
    INDEX idx_gp (gp_code)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- 5. 테마 설정 테이블 (없으면 생성)
CREATE TABLE IF NOT EXISTS iw_theme_setting (
    setting_no INT AUTO_INCREMENT PRIMARY KEY,
    ep_code VARCHAR(50),
    gp_code VARCHAR(50),
    theme_name VARCHAR(100),
    theme_color VARCHAR(20),
    theme_font VARCHAR(100),
    theme_config TEXT,
    reg_date DATETIME,
    INDEX idx_ep (ep_code),
    INDEX idx_gp (gp_code)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- 6. 쇼핑몰 관련 테이블 (이미 있을 수 있음)
CREATE TABLE IF NOT EXISTS iw_shop_data (
    product_no INT AUTO_INCREMENT PRIMARY KEY,
    ep_code VARCHAR(50),
    gp_code VARCHAR(50),
    product_name VARCHAR(200),
    product_price INT,
    product_stock INT,
    reg_date DATETIME,
    INDEX idx_ep (ep_code)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- 7. 출판 관련 테이블 (이미 있을 수 있음)
CREATE TABLE IF NOT EXISTS iw_publishing_books (
    book_no INT AUTO_INCREMENT PRIMARY KEY,
    ep_code VARCHAR(50),
    gp_code VARCHAR(50),
    book_title VARCHAR(200),
    book_author VARCHAR(100),
    book_isbn VARCHAR(50),
    reg_date DATETIME,
    INDEX idx_ep (ep_code)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;