-- =====================================================================
-- seed-knowledge-base.sql — seed knowledge_base rows for a tenant
--
-- Usage:
--   1. Set @tenant_id below to a real tenant id (check with:
--        SELECT id, business_name FROM tenants;)
--   2. Edit the INSERT rows below to match your real business, or
--      leave the sample HVAC-flavored set as-is for a quick test call —
--      it's written with a few DISTINCTIVE facts (a specific dollar
--      figure, a specific radius, "ninety day warranty") so that
--      during a live test call you can ask a matching question and
--      listen for that EXACT fact coming back. That's what actually
--      proves the lookupKnowledgeBase tool fired, rather than the AI
--      guessing a plausible-sounding but ungrounded answer.
--   3. Run:
--        mysql -h <db_host> -u <user> -p ai_front_desk < seed-knowledge-base.sql
--
-- Note: knowledge_base has no unique constraint on (tenant_id,
-- question) — re-running this file for the same tenant will insert
-- duplicates unless you uncomment the DELETE line below first.
-- =====================================================================

-- Self-defending: works even if you forgot to pass the DB name on the
-- command line, or ran this via `mysql < file.sql` / `source file.sql`
-- without a preceding `USE`. Change this if your DB is named differently.
USE ai_front_desk;

SET @tenant_id = 2;

-- Sanity check — if this returns no rows, STOP and fix @tenant_id above.
SELECT id, business_name FROM tenants WHERE id = @tenant_id;

-- Uncomment this line if you're RE-seeding and want to replace this
-- tenant's existing rows instead of appending to them:
-- DELETE FROM knowledge_base WHERE tenant_id = @tenant_id;

INSERT INTO knowledge_base (tenant_id, category, question, answer, is_active, created_at, updated_at) VALUES
(@tenant_id, 'hours', 'What are your business hours?',
 'We are open Monday through Friday, 8am to 6pm, and Saturday 9am to 2pm. Closed Sundays.',
 1, NOW(), NOW()),

(@tenant_id, 'pricing', 'How much does a standard service call cost?',
 'Our standard diagnostic service call fee is eighty nine dollars, which is credited toward the repair if you go ahead with it.',
 1, NOW(), NOW()),

(@tenant_id, 'coverage_area', 'What areas do you service?',
 'We service the greater metro area within a thirty mile radius of downtown, including all surrounding suburbs.',
 1, NOW(), NOW()),

(@tenant_id, 'policy', 'Do you offer same-day appointments?',
 'Yes, we offer same-day appointments for emergency repairs booked before noon, subject to technician availability.',
 1, NOW(), NOW()),

(@tenant_id, 'policy', 'Do you offer any warranty on repairs?',
 'All repairs come with a ninety day labor warranty, and parts carry the manufacturer warranty, typically one to five years.',
 1, NOW(), NOW());

-- Confirm what's actually in there now for this tenant.
SELECT id, category, question, is_active, created_at
FROM knowledge_base
WHERE tenant_id = @tenant_id
ORDER BY id DESC;
