CREATE TABLE IF NOT EXISTS company_settings (id uuid PRIMARY KEY DEFAULT gen_random_uuid(), company_name varchar(255) NOT NULL, tax_id varchar(100), contact_email varchar(255), phone varchar(50), address jsonb, logo_key text, currency_code varchar(10), timezone varchar(100), updated_by uuid REFERENCES users(id), updated_at timestamptz NOT NULL DEFAULT now());
CREATE TABLE IF NOT EXISTS api_configurations (id uuid PRIMARY KEY DEFAULT gen_random_uuid(), name varchar(120) NOT NULL, base_url text, config jsonb NOT NULL DEFAULT '{}'::jsonb, status boolean NOT NULL DEFAULT true, updated_by uuid REFERENCES users(id), updated_at timestamptz NOT NULL DEFAULT now());
CREATE TABLE IF NOT EXISTS survey_templates (id uuid PRIMARY KEY DEFAULT gen_random_uuid(), name varchar(255) NOT NULL, description text, schema jsonb NOT NULL DEFAULT '{}'::jsonb, status varchar(20) NOT NULL DEFAULT 'draft', created_by uuid REFERENCES users(id), created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now());
CREATE TABLE IF NOT EXISTS survey_responses (id uuid PRIMARY KEY DEFAULT gen_random_uuid(), template_id uuid NOT NULL REFERENCES survey_templates(id), project_id uuid REFERENCES projects(id), respondent_id uuid REFERENCES users(id), response jsonb NOT NULL DEFAULT '{}'::jsonb, submitted_at timestamptz, created_at timestamptz NOT NULL DEFAULT now());
