-- +goose Up
-- SQL in this section is executed when the migration is applied
CREATE TABLE IF NOT EXISTS setup_info (
    id SERIAL PRIMARY KEY,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    deleted_at TIMESTAMP WITH TIME ZONE,
    status VARCHAR(20) NOT NULL DEFAULT 'pending',
    skipped_at TIMESTAMP WITH TIME ZONE,
    completed_at TIMESTAMP WITH TIME ZONE,
    smtp_configured BOOLEAN NOT NULL DEFAULT false,
    club_imported BOOLEAN NOT NULL DEFAULT false
);

CREATE TABLE IF NOT EXISTS club_info (
    id SERIAL PRIMARY KEY,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    deleted_at TIMESTAMP WITH TIME ZONE,
    setup_info_id INTEGER NOT NULL REFERENCES setup_info(id) ON DELETE CASCADE,
    facr_club_id VARCHAR(255) UNIQUE NOT NULL,
    name VARCHAR(255) NOT NULL,
    short_name VARCHAR(100),
    logo_url TEXT,
    primary_color VARCHAR(7),
    secondary_color VARCHAR(7),
    text_color VARCHAR(7)
);

-- Create initial setup info record if it doesn't exist
INSERT INTO setup_info (id, status, created_at, updated_at)
SELECT 1, 'pending', NOW(), NOW()
WHERE NOT EXISTS (SELECT 1 FROM setup_info WHERE id = 1);
