-- Create contact_categories table
CREATE TABLE IF NOT EXISTS contact_categories (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL UNIQUE,
    description TEXT,
    display_order INT DEFAULT 0,
    is_active BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    deleted_at TIMESTAMP
);

CREATE INDEX idx_contact_categories_display_order ON contact_categories(display_order);
CREATE INDEX idx_contact_categories_is_active ON contact_categories(is_active);

-- Create contacts table
CREATE TABLE IF NOT EXISTS contacts (
    id SERIAL PRIMARY KEY,
    category_id INT REFERENCES contact_categories(id) ON DELETE SET NULL,
    name VARCHAR(255) NOT NULL,
    position VARCHAR(255),
    email VARCHAR(255),
    phone VARCHAR(100),
    image_url VARCHAR(500),
    description TEXT,
    display_order INT DEFAULT 0,
    is_active BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    deleted_at TIMESTAMP
);

CREATE INDEX idx_contacts_category_id ON contacts(category_id);
CREATE INDEX idx_contacts_display_order ON contacts(display_order);
CREATE INDEX idx_contacts_is_active ON contacts(is_active);

-- Add contact/location fields to settings table
ALTER TABLE settings ADD COLUMN IF NOT EXISTS contact_address VARCHAR(500);
ALTER TABLE settings ADD COLUMN IF NOT EXISTS contact_city VARCHAR(255);
ALTER TABLE settings ADD COLUMN IF NOT EXISTS contact_zip VARCHAR(20);
ALTER TABLE settings ADD COLUMN IF NOT EXISTS contact_country VARCHAR(100);
ALTER TABLE settings ADD COLUMN IF NOT EXISTS contact_phone VARCHAR(100);
ALTER TABLE settings ADD COLUMN IF NOT EXISTS contact_email VARCHAR(255);
ALTER TABLE settings ADD COLUMN IF NOT EXISTS location_latitude DECIMAL(10, 8);
ALTER TABLE settings ADD COLUMN IF NOT EXISTS location_longitude DECIMAL(11, 8);
ALTER TABLE settings ADD COLUMN IF NOT EXISTS map_zoom_level INT DEFAULT 15;
ALTER TABLE settings ADD COLUMN IF NOT EXISTS map_style VARCHAR(255);
ALTER TABLE settings ADD COLUMN IF NOT EXISTS show_map_on_homepage BOOLEAN DEFAULT FALSE;
