
    ;j	                        d dl mZ d dlZd dlZd dlmZ d dlmZ  ee      j                  dz  Z
dZe
fddZe
fddZed	k(  r e         ed
 e               yy)    )annotationsN)Path)load_all_projectszemail_agent.dba  
CREATE TABLE IF NOT EXISTS product_catalog (
  project_id TEXT PRIMARY KEY,
  title TEXT NOT NULL,
  status TEXT,
  target_industries TEXT NOT NULL,
  customer_problem TEXT,
  potential_score REAL,
  confidence TEXT,
  source_file TEXT NOT NULL,
  synced_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS lead_project_matches (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  contact_id INTEGER NOT NULL,
  project_id TEXT NOT NULL,
  industry_fit REAL NOT NULL DEFAULT 0,
  problem_pressure REAL NOT NULL DEFAULT 0,
  company_fit REAL NOT NULL DEFAULT 0,
  technical_fit REAL NOT NULL DEFAULT 0,
  economic_value REAL NOT NULL DEFAULT 0,
  reachability REAL NOT NULL DEFAULT 0,
  evidence_quality REAL NOT NULL DEFAULT 0,
  sale_probability REAL NOT NULL DEFAULT 0,
  lead_score REAL NOT NULL DEFAULT 0,
  rationale TEXT,
  evidence_json TEXT,
  status TEXT NOT NULL DEFAULT 'researched',
  human_gate TEXT NOT NULL DEFAULT 'pending',
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  UNIQUE(contact_id, project_id)
);
CREATE INDEX IF NOT EXISTS idx_lpm_score ON lead_project_matches(lead_score DESC);
CREATE INDEX IF NOT EXISTS idx_lpm_gate ON lead_project_matches(human_gate, status);
c                    t        j                  |       5 }|j                  t               |j	                          d d d        y # 1 sw Y   y xY w)N)sqlite3connectexecutescriptSCHEMAcommit)db_pathconns     v2_schema.pyinit_schemar   0   s<    		! T6"  s   &AAc           
        t               }t        j                  |       5 }|D ]  }|j                  |j                  |j
                  t        j                  |j                  d      |j                  |j                  |j                  |j                  f}|j                  d|        |j                          d d d        t        |      S # 1 sw Y   t        |      S xY w)NF)ensure_asciizINSERT OR REPLACE INTO product_catalog (project_id,title,status,target_industries,customer_problem,potential_score,confidence,source_file,synced_at) VALUES (?,?,?,?,?,?,?,?,CURRENT_TIMESTAMP))r   r   r   
project_idtitlestatusjsondumpstarget_industriescustomer_problempotential_score
confidencesource_fileexecuter   len)r   projectsr   pvaluess        r   sync_projectsr!   6   s     "H		! T 	Aaggqxx

1..UC""A$5$5amm	F LL= ?E		 	 x= x=s   BCC__main__zsynced_projects=)r   r   returnNone)r   r   r#   int)
__future__r   r   r   pathlibr   project_catalogr   __file__parentDB_PATHr
   r   r!   __name__print     r   <module>r0      sl    "    -
x.

"2
2#
L !(  #* ( zM	]_-
./ r/   