-- Mowing sessions to track mowing activity with GPS
CREATE TABLE IF NOT EXISTS mowing_sessions (
  id SERIAL PRIMARY KEY,
  user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
  property_id INTEGER REFERENCES properties(id) ON DELETE CASCADE,
  equipment_id INTEGER REFERENCES user_equipment(id),
  cut_height_inches DECIMAL(4,2),
  direction VARCHAR(20) CHECK (direction IN ('N_S','E_W','NE_SW','NW_SE','CIRCULAR')),
  session_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  gps_track JSON,
  duration_seconds INTEGER,
  total_distance_meters DECIMAL(10,2),
  average_speed_mph DECIMAL(5,2),
  area_covered_sqft DECIMAL(12,2),
  notes TEXT,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS mowing_session_sections (
  id SERIAL PRIMARY KEY,
  session_id INTEGER REFERENCES mowing_sessions(id) ON DELETE CASCADE,
  lawn_section_id INTEGER REFERENCES lawn_sections(id) ON DELETE CASCADE
);

CREATE INDEX IF NOT EXISTS idx_mowing_sessions_user_id ON mowing_sessions(user_id);
CREATE INDEX IF NOT EXISTS idx_mowing_sessions_property_id ON mowing_sessions(property_id);
CREATE INDEX IF NOT EXISTS idx_mowing_session_sections_session_id ON mowing_session_sections(session_id);

