-- V13: Info Board (Schwarzes Brett) tables

CREATE TABLE info_board_posts (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    club_id UUID NOT NULL REFERENCES clubs(id),
    title VARCHAR(200) NOT NULL,
    content TEXT NOT NULL,
    category VARCHAR(50) NOT NULL,
    is_pinned BOOLEAN DEFAULT FALSE,
    is_archived BOOLEAN DEFAULT FALSE,
    author_id UUID NOT NULL REFERENCES users(id),
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW(),
    tenant_id UUID NOT NULL
);

CREATE TABLE post_attachments (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    post_id UUID NOT NULL REFERENCES info_board_posts(id) ON DELETE CASCADE,
    filename VARCHAR(255) NOT NULL,
    content_type VARCHAR(100),
    file_size BIGINT,
    storage_path VARCHAR(500) NOT NULL,
    created_at TIMESTAMP DEFAULT NOW(),
    tenant_id UUID NOT NULL
);

CREATE TABLE post_read_status (
    post_id UUID NOT NULL REFERENCES info_board_posts(id) ON DELETE CASCADE,
    member_id UUID NOT NULL REFERENCES members(id) ON DELETE CASCADE,
    read_at TIMESTAMP DEFAULT NOW(),
    PRIMARY KEY (post_id, member_id)
);

CREATE INDEX idx_info_board_posts_club_id ON info_board_posts(club_id);
CREATE INDEX idx_info_board_posts_category ON info_board_posts(category);
CREATE INDEX idx_info_board_posts_pinned ON info_board_posts(is_pinned) WHERE is_pinned = TRUE;
CREATE INDEX idx_info_board_posts_tenant ON info_board_posts(tenant_id);
CREATE INDEX idx_post_attachments_post_id ON post_attachments(post_id);
