CREATE TABLE IF NOT EXISTS pat_area (
    id BIGSERIAL PRIMARY KEY, area_name VARCHAR(100), area_code VARCHAR(32) UNIQUE,
    description VARCHAR(500), center_lng NUMERIC(10,6), center_lat NUMERIC(10,6),
    boundary TEXT, radius DOUBLE PRECISION, status VARCHAR(20) DEFAULT 'active',
    created_at TIMESTAMPTZ DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS pat_route_setup (
    id BIGSERIAL PRIMARY KEY, route_name VARCHAR(100), route_code VARCHAR(32) UNIQUE,
    area_id BIGINT, area_name VARCHAR(100), checkpoint_count INT DEFAULT 0,
    checkpoint_list TEXT, total_distance DOUBLE PRECISION, estimated_minutes INT,
    status VARCHAR(20) DEFAULT 'active', remark VARCHAR(500),
    created_at TIMESTAMPTZ DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS pat_form (
    id BIGSERIAL PRIMARY KEY, form_name VARCHAR(100), form_code VARCHAR(32) UNIQUE,
    form_type VARCHAR(30), field_config TEXT, status VARCHAR(20) DEFAULT 'active',
    remark VARCHAR(500), created_at TIMESTAMPTZ DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS pat_template (
    id BIGSERIAL PRIMARY KEY, template_name VARCHAR(100), template_code VARCHAR(32) UNIQUE,
    route_id BIGINT, route_name VARCHAR(100), form_id BIGINT, form_name VARCHAR(100),
    schedule_type VARCHAR(20), schedule_config TEXT, status VARCHAR(20) DEFAULT 'active',
    remark VARCHAR(500), created_at TIMESTAMPTZ DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT NOW()
);
