-- 주간보고 공유 이력 테이블
-- 실행: psql -d weeklyreport -f create_report_share_log.sql

CREATE TABLE IF NOT EXISTS wr_report_share_log (
  share_id SERIAL PRIMARY KEY,
  report_id INTEGER NOT NULL REFERENCES wr_weekly_report(report_id),
  shared_to VARCHAR(255) NOT NULL,  -- 공유 대상 (이메일 또는 그룹명)
  shared_type VARCHAR(50) NOT NULL DEFAULT 'GOOGLE_GROUP',  -- GOOGLE_GROUP, EMAIL, SLACK 등
  shared_by INTEGER NOT NULL REFERENCES wr_employee_info(employee_id),
  shared_at TIMESTAMP DEFAULT NOW(),
  message_id VARCHAR(255),  -- Gmail 메시지 ID 등
  share_status VARCHAR(20) DEFAULT 'SUCCESS',  -- SUCCESS, FAILED
  error_message TEXT
);

CREATE INDEX IF NOT EXISTS idx_report_share_report_id ON wr_report_share_log(report_id);
CREATE INDEX IF NOT EXISTS idx_report_share_shared_by ON wr_report_share_log(shared_by);

COMMENT ON TABLE wr_report_share_log IS '주간보고 공유 이력';
COMMENT ON COLUMN wr_report_share_log.shared_to IS '공유 대상 (이메일, 그룹 등)';
COMMENT ON COLUMN wr_report_share_log.shared_type IS '공유 방식 (GOOGLE_GROUP, EMAIL, SLACK 등)';
