-- 사용자 테이블
CREATE TABLE IF NOT EXISTS users (
    id SERIAL PRIMARY KEY,
    username VARCHAR(50) UNIQUE NOT NULL,
    hashed_password VARCHAR(255) NOT NULL,
    full_name VARCHAR(100),
    role VARCHAR(20) DEFAULT 'user',
    is_active BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 이슈 테이블
CREATE TABLE IF NOT EXISTS issues (
    id SERIAL PRIMARY KEY,
    photo_path VARCHAR(255),
    category VARCHAR(50) NOT NULL,
    description TEXT NOT NULL,
    status VARCHAR(20) DEFAULT 'new',
    reporter_id INTEGER REFERENCES users(id),
    report_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    work_hours FLOAT DEFAULT 0,
    detail_notes TEXT
);

-- 일일 공수 테이블
CREATE TABLE IF NOT EXISTS daily_works (
    id SERIAL PRIMARY KEY,
    date DATE NOT NULL UNIQUE,
    worker_count INTEGER NOT NULL,
    regular_hours FLOAT NOT NULL,
    overtime_workers INTEGER DEFAULT 0,
    overtime_hours FLOAT DEFAULT 0,
    overtime_total FLOAT DEFAULT 0,
    total_hours FLOAT NOT NULL,
    created_by_id INTEGER REFERENCES users(id),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 인덱스 생성
CREATE INDEX idx_issues_reporter_id ON issues(reporter_id);
CREATE INDEX idx_issues_status ON issues(status);
CREATE INDEX idx_issues_report_date ON issues(report_date);
CREATE INDEX idx_daily_works_date ON daily_works(date);
