-- ============================================================
-- Nxtgauge Knowledge Base Seed
-- Run AFTER migrations. Safe to re-run (ON CONFLICT DO NOTHING).
-- ============================================================

DO $$
DECLARE
  cat_getting_started   UUID;
  cat_account           UUID;
  cat_companies         UUID;
  cat_job_seekers       UUID;
  cat_customers         UUID;
  cat_professionals     UUID;
  cat_tracecoins        UUID;
  cat_policies          UUID;
BEGIN

-- ── Categories ───────────────────────────────────────────────────────────────

INSERT INTO kb_categories (name, slug, description, display_order)
VALUES ('Getting Started', 'getting-started', 'New to Nxtgauge? Start here.', 10)
ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_categories (name, slug, description, display_order)
VALUES ('Account & Verification', 'account-verification', 'Manage your account, verification status, and security.', 20)
ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_categories (name, slug, description, display_order)
VALUES ('For Companies', 'for-companies', 'Job posting, applications, and hiring on Nxtgauge.', 30)
ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_categories (name, slug, description, display_order)
VALUES ('For Job Seekers', 'for-job-seekers', 'Finding jobs, applying, and tracking applications.', 40)
ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_categories (name, slug, description, display_order)
VALUES ('For Customers', 'for-customers', 'Posting service requirements and connecting with professionals.', 50)
ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_categories (name, slug, description, display_order)
VALUES ('For Professionals', 'for-professionals', 'Marketplace, leads, portfolio, and services.', 60)
ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_categories (name, slug, description, display_order)
VALUES ('Tracecoins & Billing', 'tracecoins-billing', 'How Tracecoins work, purchasing, and billing.', 70)
ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_categories (name, slug, description, display_order)
VALUES ('Platform Policies', 'platform-policies', 'Rules, approvals, and community guidelines.', 80)
ON CONFLICT (slug) DO NOTHING;

-- Fetch IDs
SELECT id INTO cat_getting_started FROM kb_categories WHERE slug = 'getting-started';
SELECT id INTO cat_account         FROM kb_categories WHERE slug = 'account-verification';
SELECT id INTO cat_companies       FROM kb_categories WHERE slug = 'for-companies';
SELECT id INTO cat_job_seekers     FROM kb_categories WHERE slug = 'for-job-seekers';
SELECT id INTO cat_customers       FROM kb_categories WHERE slug = 'for-customers';
SELECT id INTO cat_professionals   FROM kb_categories WHERE slug = 'for-professionals';
SELECT id INTO cat_tracecoins      FROM kb_categories WHERE slug = 'tracecoins-billing';
SELECT id INTO cat_policies        FROM kb_categories WHERE slug = 'platform-policies';

-- ── Articles ─────────────────────────────────────────────────────────────────

-- ── Getting Started ──────────────────────────────────────────────────────────

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_getting_started,
  'What is Nxtgauge?',
  'what-is-nxtgauge',
  'An overview of the Nxtgauge platform and who it is for.',
  'Nxtgauge is a multi-role platform connecting companies, job seekers, service customers, and verified professionals in India. Built to reduce the friction of finding work and hiring talent, it uses a token economy (Tracecoins) to ensure only serious parties engage.

Who is Nxtgauge for?
- Companies: Post jobs, review applications, and hire candidates quickly.
- Job Seekers: Browse verified job listings and apply with a single click.
- Customers: Post service requirements (photography, tutoring, development, etc.) and connect with verified professionals.
- Professionals: Discover service requirements from customers, send lead requests, and grow your client base.

Why Tracecoins?
The Tracecoin system filters out low-quality engagement. Companies pay for additional job slots and candidate contact views. Professionals reserve Tracecoins when requesting a customer lead — ensuring only genuine interest reaches the customer.

All content on Nxtgauge goes through an approval workflow. Jobs, requirements, and professional profiles are reviewed by the Nxtgauge team before they go live, keeping the platform trustworthy.',
  '{}',
  ARRAY['overview', 'platform', 'getting-started'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_getting_started,
  'How to create an account',
  'how-to-create-an-account',
  'Step-by-step guide to registering your Nxtgauge account.',
  'Creating an account on Nxtgauge is free and takes under two minutes.

Step 1: Go to nxtgauge.com and click "Sign Up".
Step 2: Enter your full name, email address, and a strong password.
Step 3: Check your email for a verification code and enter it on the verification page.
Step 4: Once verified, you will be prompted to choose your first role.

After registration your account exists but has no role attached. You must complete onboarding for at least one role before accessing any role-specific features.

Tips:
- Use a personal email address you check regularly. All platform notifications including approval outcomes are sent here.
- Your password must be at least 8 characters.
- If you do not receive the verification email within 5 minutes, check your spam folder or click "Resend code" on the verification page.',
  '{}',
  ARRAY['register', 'account', 'sign-up', 'email-verification'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_getting_started,
  'Choosing your role on Nxtgauge',
  'choosing-your-role',
  'Understand the different roles available and how to pick the right one for you.',
  'Nxtgauge supports multiple roles on a single account. After verifying your email, you will be asked to choose your first role.

Available roles:
- Company: For businesses that want to post jobs and hire employees.
- Job Seeker: For individuals looking for employment opportunities.
- Customer: For anyone who needs a service (photography, tutoring, development work, etc.).
- Professional: For service providers — Photographer, Makeup Artist, Tutor, Developer, Video Editor, Graphic Designer, Social Media Manager, Fitness Trainer, or Catering Service.

Can I have more than one role?
Yes. You can add additional roles from the Explore section of your dashboard. Each role has its own onboarding form and must be verified separately. Once approved, you can switch between roles using the sidebar.

Which role should I pick first?
Choose the role that reflects your primary purpose on the platform. If you are a developer who also wants to hire for your startup, register as a Developer first, complete verification, then add a Company role.',
  '{}',
  ARRAY['roles', 'getting-started', 'onboarding'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_getting_started,
  'How to switch between roles',
  'switching-between-roles',
  'Nxtgauge lets you hold multiple roles. Learn how to switch between them.',
  'If you have been approved for more than one role, you can switch between them at any time without logging out.

How to switch:
1. Look at the sidebar in your dashboard. Near the top you will see your current active role.
2. Click "Switch Role" or navigate to the Explore page.
3. Select the role you want to switch to and confirm.

Your dashboard, navigation, and available features will immediately update to reflect the selected role.

Important notes:
- Each role has its own dashboard, data, and settings. Switching roles does not mix data between roles.
- If a role is still pending verification, you can switch to it but most features will be locked until approval is complete.
- You can only be active in one role at a time per session.',
  '{}',
  ARRAY['roles', 'switch-role', 'dashboard'],
  true
) ON CONFLICT (slug) DO NOTHING;

-- ── Account & Verification ───────────────────────────────────────────────────

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_account,
  'How verification works',
  'how-verification-works',
  'Understand the document review process, approval outcomes, and timeline.',
  'Every role on Nxtgauge requires verification before you can access full platform features. Verification is how we ensure all participants are genuine and trustworthy.

The verification process:
1. Complete onboarding: Fill out your role-specific onboarding form. Each role has a different set of fields — for example, companies provide business details, professionals provide credentials and portfolio links.
2. Submit documents: Upload the required identity and role documents (see the "What documents are required?" article for the full list per role).
3. Admin review: The Nxtgauge team reviews your submission. This typically takes 1–3 business days.
4. Outcome: You will receive an email with one of three outcomes:
   - Approved: Your role is now live. All features are unlocked.
   - Additional documents requested: You will see a note explaining what is missing. Upload the requested items and resubmit.
   - Rejected: You will receive a reason. You may address the issue and resubmit.

During review, your dashboard shows a "Pending Verification" banner. You can still explore the platform but lead requests, job applications, and marketplace access are locked.',
  '{}',
  ARRAY['verification', 'documents', 'approval', 'onboarding'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_account,
  'What documents are needed for verification?',
  'documents-required-for-verification',
  'A breakdown of the documents required by each role type.',
  'The exact documents required vary by role. Below is a summary.

All roles:
- Government-issued photo ID (Aadhaar card, PAN card, or passport)

Company:
- GST registration certificate (if applicable)
- Company incorporation document or business registration certificate
- Authorised signatory ID proof

Job Seeker:
- Latest resume (PDF)
- Any relevant certificates or degrees

Customer:
- Government-issued photo ID (same as above — no additional documents typically required)

Professionals (all 9 types):
- Government-issued photo ID
- Proof of experience or qualification relevant to your profession (e.g., degree certificate for tutors, portfolio links for photographers)
- Sample work or portfolio (images, PDFs, or URLs)

File requirements:
- Accepted formats: PDF, JPG, PNG
- Maximum file size: 5 MB per document
- Scans must be clear and legible

If your document does not meet requirements, the admin team will specify what needs to be corrected when requesting additional documents.',
  '{}',
  ARRAY['verification', 'documents', 'KYC', 'identity'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_account,
  'What happens after I submit for verification?',
  'after-submitting-verification',
  'What to expect once your documents are under review.',
  'After you submit your onboarding form and documents, here is what happens next.

Immediately after submission:
- Your role status changes to "Pending Verification".
- A confirmation email is sent to your registered address.
- Your dashboard shows a verification banner. You can still browse the platform but key actions are locked.

During review (1–3 business days):
- The Nxtgauge admin team reviews your submission.
- They may request additional documents. If so, you will receive an email listing exactly what is needed, and your dashboard will prompt you to resubmit.

On approval:
- You receive an approval email.
- Your role status changes to "Approved".
- All platform features for that role unlock immediately.
- Any actions you tried to take while pending (such as browsing the marketplace) are now available.

On rejection:
- You receive a rejection email with the specific reason.
- You can correct the issue and resubmit a new verification request.
- Rejection is not permanent — it simply means your current submission did not meet requirements.

How to check your current status:
Go to your dashboard and look at the verification banner or visit the Profile section.',
  '{}',
  ARRAY['verification', 'pending', 'approval', 'status'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_account,
  'How to reset your password',
  'how-to-reset-your-password',
  'Steps to reset a forgotten password or change your current password.',
  'Forgot your password? You can reset it at any time without contacting support.

Resetting a forgotten password:
1. Go to the login page and click "Forgot password?".
2. Enter your registered email address.
3. Check your inbox for a reset link (check spam if it does not arrive within 5 minutes).
4. Click the link and enter your new password.
5. The link expires after 30 minutes. If it expires, repeat the process.

Changing your password while logged in:
1. Go to Dashboard → Settings.
2. Click "Change Password".
3. Enter your current password and your new password twice.
4. Click Save.

Security tips:
- Use a unique password not shared with other services.
- Enable two-factor authentication once it is available (coming soon).
- If you suspect your account has been accessed without authorisation, change your password immediately and contact support@nxtgauge.com.',
  '{}',
  ARRAY['password', 'reset', 'security', 'account'],
  true
) ON CONFLICT (slug) DO NOTHING;

-- ── For Companies ─────────────────────────────────────────────────────────────

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_companies,
  'Company onboarding guide',
  'company-onboarding-guide',
  'How to complete company onboarding and get your account approved.',
  'Completing company onboarding is the first step to posting jobs on Nxtgauge.

What you will need:
- Company name, type, and industry
- GST number (optional but recommended)
- Registered address
- Company size and a brief description
- Business registration or incorporation documents

Steps:
1. After registration, select "Company" as your role.
2. Fill out the onboarding form. All required fields are marked with an asterisk.
3. Upload your company documents in the document upload section.
4. Click Submit. Your application enters the admin review queue.
5. Once approved, you receive an email and can immediately start posting jobs.

Tips for faster approval:
- Ensure your documents are clear PDFs or high-resolution images.
- Your company description should accurately reflect your business — vague descriptions may result in a request for more information.
- Use your official business email if possible.

After approval your company profile becomes visible on the platform and you receive one free job posting slot to get started.',
  ARRAY['COMPANY'],
  ARRAY['company', 'onboarding', 'verification', 'documents'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_companies,
  'How to post a job on Nxtgauge',
  'how-to-post-a-job',
  'Step-by-step guide to creating and submitting a job posting.',
  'Posting a job on Nxtgauge is straightforward once your company is verified.

Creating a job:
1. Go to Dashboard → Jobs → Create Job.
2. Fill in the job details: title, description, location, job type (full-time, part-time, contract, remote), salary range, and required experience.
3. Save as Draft to continue editing later, or click Submit to send it for admin approval.

The approval process:
All job postings are reviewed before going live. This usually takes 1 business day. You will receive an email when your job is approved and live.

Job slot limits:
- Every verified company receives 1 free job posting slot.
- Additional slots can be purchased using Tracecoins from the Packages page.
- Each job slot is consumed when a job is submitted. Closing or deleting a draft does not consume a slot.

Auto-expiry:
Jobs automatically expire after 30 days. You will receive a reminder email 3 days before expiry. To extend, close and repost the job.

Editing a live job:
You can edit a live job''s description and details, but changing the role title or key requirements will require re-approval.',
  ARRAY['COMPANY'],
  ARRAY['jobs', 'posting', 'hiring', 'approval'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_companies,
  'Understanding the job approval process',
  'job-approval-process',
  'Why jobs are reviewed and what can cause a rejection.',
  'Every job posted on Nxtgauge goes through an admin review before it reaches job seekers. This protects candidates from fraudulent or misleading listings.

Why approval is required:
- It ensures job titles and descriptions are accurate and not misleading.
- It prevents spam listings and duplicate postings.
- It maintains the quality of the job board for candidates.

What admin looks for:
- Clear and honest job title and description.
- Realistic compensation range (or clearly marked as "competitive").
- Legitimate company verification documents already on file.
- No discriminatory language.

Reasons for rejection:
- Vague or incomplete job description.
- Misleading title (e.g., "Earn ₹50,000/day from home").
- Salary or requirements inconsistent with the role.
- Duplicate of an existing live listing.

After rejection:
You will receive an email with the specific reason. Edit your job to address the issue and resubmit. Your job slot is not consumed on a rejected listing — it is only consumed on approval.',
  ARRAY['COMPANY'],
  ARRAY['jobs', 'approval', 'review', 'rejection'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_companies,
  'How to manage job applications',
  'managing-job-applications',
  'Review, shortlist, and update the status of applications for your jobs.',
  'Once your job is live, applications start coming in. Here is how to manage them effectively.

Viewing applications:
Go to Dashboard → Jobs → select a job → Applications. You will see a list of all applicants with their name, headline, application date, and current status.

Application statuses you can set:
- Shortlisted: Candidate is worth a closer look.
- Interview: You have scheduled or plan to schedule an interview.
- Offered: You have made a job offer.
- Rejected: Candidate is not suitable for this role.
- Hired: Position has been filled by this candidate.

Viewing candidate details:
Basic profile information is visible for free. To see a candidate''s full contact details (phone number and email), you need to use a contact view. Each company receives 30 free contact views. Additional views can be purchased via the Packages page using Tracecoins.

Once you view contact details, you can reach out to the candidate directly via phone or email.

Candidate notifications:
Candidates receive email notifications when you update their application status to Shortlisted, Interview, Offered, or Rejected. This keeps them informed without requiring you to send manual emails.',
  ARRAY['COMPANY'],
  ARRAY['applications', 'hiring', 'shortlist', 'candidates'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_companies,
  'Viewing candidate contact details',
  'viewing-candidate-contact-details',
  'How contact view credits work and how to unlock a candidate''s contact information.',
  'To protect candidate privacy, Nxtgauge does not expose phone numbers and email addresses by default. Instead, companies use Contact Views to unlock this information for specific candidates.

How contact views work:
- Each verified company receives 30 free contact views.
- Each time you click "View Contact Details" for a candidate, 1 contact view is consumed.
- Once consumed, you can view that candidate''s details unlimited times — the credit is not re-charged for the same candidate.
- Contact view credits do not expire.

Purchasing additional views:
Go to Dashboard → Packages to see available contact view packages. Packages are purchased with Tracecoins. See the "What are Tracecoins?" article to learn how to buy them.

What contact details are revealed:
- Full name (already visible)
- Email address
- Phone number (if the candidate has provided one)

You can then contact the candidate directly via your preferred channel — Nxtgauge does not intermediate the communication after this point.',
  ARRAY['COMPANY'],
  ARRAY['contact-views', 'candidates', 'tracecoins', 'privacy'],
  true
) ON CONFLICT (slug) DO NOTHING;

-- ── For Job Seekers ───────────────────────────────────────────────────────────

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_job_seekers,
  'Job seeker onboarding guide',
  'job-seeker-onboarding-guide',
  'How to set up your job seeker profile and get verified.',
  'Your job seeker profile is what companies see when you apply. A complete, accurate profile significantly improves your chances of being shortlisted.

What to prepare:
- Updated resume (PDF, max 5 MB)
- A short professional headline (e.g., "Full-Stack Developer with 3 years experience")
- Skills list
- Work experience and education history
- Government-issued photo ID for verification

Onboarding steps:
1. Choose "Job Seeker" as your role after registration (or add it from the Explore page).
2. Complete the onboarding form — fill in your headline, skills, experience, and education.
3. Upload your resume and identity document.
4. Submit for review.

Verification:
Your profile is reviewed to confirm you are a genuine candidate. Once approved, all live jobs on the platform become visible and you can apply immediately.',
  ARRAY['JOB_SEEKER'],
  ARRAY['job-seeker', 'onboarding', 'profile', 'resume'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_job_seekers,
  'How to apply for jobs',
  'how-to-apply-for-jobs',
  'Browsing the job feed and submitting applications on Nxtgauge.',
  'Once your job seeker profile is verified, you can start applying to jobs immediately.

Browsing jobs:
Go to Dashboard → Jobs → Browse. You will see all currently live and approved jobs. Filter by:
- Location
- Job type (full-time, part-time, contract, remote)
- Category or industry
- Keyword search

Applying to a job:
1. Click on a job listing to view its full details.
2. If it is a match, click "Apply".
3. An application form appears. You can optionally add a cover letter.
4. Select which resume you want to attach (your uploaded resume is pre-selected).
5. Click Submit.

Application limits:
- You can have a maximum of 50 active applications at any time.
- Once you withdraw an application or a company marks it as Hired or Rejected, that slot frees up.
- You cannot apply to the same job twice.

After applying:
You will receive a confirmation email. Track the status of your application under Dashboard → Applications.',
  ARRAY['JOB_SEEKER'],
  ARRAY['apply', 'jobs', 'applications', 'cover-letter'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_job_seekers,
  'Tracking your job applications',
  'tracking-your-applications',
  'How to monitor the status of every application you have submitted.',
  'Nxtgauge keeps all your applications in one place so you always know where you stand.

Viewing your applications:
Go to Dashboard → Applications. You will see a list of all your submitted applications with:
- Company name and job title
- Date applied
- Current status

Application statuses:
- Applied: Your application has been submitted and is under review.
- Shortlisted: The company has marked you as a potential fit.
- Interview: The company wants to interview you. Check your email for direct contact from them.
- Offered: The company has extended a job offer.
- Rejected: You were not selected for this position. This happens to everyone — keep applying.
- Hired: You accepted a role (this is updated by the company).
- Withdrawn: You voluntarily withdrew your application.

Email notifications:
You receive email notifications whenever a company updates your status to Shortlisted, Interview, Offered, or Rejected. Notifications also appear in your dashboard under the bell icon.',
  ARRAY['JOB_SEEKER'],
  ARRAY['applications', 'status', 'tracking', 'notifications'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_job_seekers,
  'How to withdraw an application',
  'how-to-withdraw-an-application',
  'Cancel an application you no longer want to pursue.',
  'Changed your mind about a role? You can withdraw an application at any time while it is still active.

How to withdraw:
1. Go to Dashboard → Applications.
2. Find the application you want to withdraw.
3. Click "Withdraw" and confirm.

What happens after withdrawal:
- The application is marked as Withdrawn and the company can no longer see it in their active applicant list.
- Your application slot is freed up so you can apply to another job (up to your 50-application limit).
- You cannot re-apply to the same job once you have withdrawn. Apply carefully.

When you cannot withdraw:
If a company has already marked your application as Hired or Rejected, withdrawal is no longer available — the application is already closed.

A note on etiquette:
If you have already been in contact with the company or interviewed, it is good practice to send them a brief email explaining you are withdrawing before doing so on the platform.',
  ARRAY['JOB_SEEKER'],
  ARRAY['applications', 'withdraw', 'cancel'],
  true
) ON CONFLICT (slug) DO NOTHING;

-- ── For Customers ─────────────────────────────────────────────────────────────

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_customers,
  'Customer onboarding guide',
  'customer-onboarding-guide',
  'How to set up your customer account and start receiving professional proposals.',
  'As a customer, you can post service requirements and receive proposals from verified professionals in the category you need.

What you need:
- Basic personal details (name, phone number, city)
- Government-issued photo ID for verification (Aadhaar, PAN, or passport)
- A clear idea of the service you need

Onboarding steps:
1. Select "Customer" as your role after registration.
2. Fill in your customer profile details.
3. Upload your identity document.
4. Submit for review.

Verification is usually completed within 1–2 business days. Once approved, you can immediately post your first service requirement.

What happens next:
Once you post a requirement and it is approved (see "How requirements work"), verified professionals in the relevant category can see it on their marketplace feed and send you a lead request.',
  ARRAY['CUSTOMER'],
  ARRAY['customer', 'onboarding', 'profile', 'verification'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_customers,
  'How to post a service requirement',
  'how-to-post-a-requirement',
  'Create a requirement to attract verified professionals for your service need.',
  'A requirement is a posting that describes the service you need. Verified professionals in that category can see it and send you a request to connect.

Steps to post a requirement:
1. Go to Dashboard → Requirements → New Requirement.
2. Select the profession category (e.g., Photography, Tutoring, Web Development).
3. Fill in the requirement form:
   - Title: A short description of what you need (e.g., "Wedding photographer for Feb ceremony").
   - Description: More detail — date, duration, location, specific requirements.
   - Budget: Your budget range in INR.
   - Preferred date: When you need the service.
4. Submit. Your requirement enters the admin approval queue.
5. Once approved (usually within 1 business day), your requirement goes live on the professional marketplace.

Requirement limits:
You can have a maximum of 2 active requirements at any time. Once one is closed, expired, or you have accepted a professional, you can post another.

Requirements automatically expire after 7 days if no action is taken.',
  ARRAY['CUSTOMER'],
  ARRAY['requirements', 'posting', 'professionals', 'service'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_customers,
  'Managing professional requests for your requirement',
  'managing-professional-requests',
  'How to review, accept, and reject professional lead requests.',
  'Once your requirement is live, professionals can send you a request to connect. Here is how to manage those requests.

Viewing requests:
Go to Dashboard → Requirements → select your requirement → Requests. You will see a list of professionals who have requested to work with you.

Each request shows:
- Professional name and profession type
- A brief profile summary
- Their rating and portfolio (if available)

Accepting a request:
1. Click "Accept" on a professional''s request.
2. Their full contact details are revealed to you immediately.
3. You can now reach out to them directly via phone or email to discuss the project.
4. A notification is sent to the professional confirming their request was accepted.

Rejecting a request:
Click "Reject" to decline a professional''s request. They will receive a notification. Their reserved Tracecoins are returned to them.

Limits:
- You can accept up to 10 professionals per requirement. Once 10 are accepted, the requirement automatically closes to new requests.
- Accepted professionals'' contact details are permanently visible to you — you do not need to accept more than you need.

Best practice: Review the professional''s portfolio and services before accepting. The platform reveals contact details on acceptance, so treat it as your shortlisting step.',
  ARRAY['CUSTOMER'],
  ARRAY['requirements', 'requests', 'professionals', 'accept', 'reject'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_customers,
  'How requirements work: approval and expiry',
  'requirement-approval-and-expiry',
  'The lifecycle of a service requirement from creation to closure.',
  'Understanding the lifecycle of a requirement helps you plan your service needs effectively.

Lifecycle stages:

1. Draft: You are still filling in the form. Not visible to professionals.
2. Pending Approval: Submitted and under review by the Nxtgauge team.
3. Live: Approved and visible to professionals in the relevant category.
4. Closed: Manually closed by you, or auto-closed after 10 acceptances.
5. Expired: Automatically expired after 7 days with no activity.

Why approval is required:
Nxtgauge reviews requirements to ensure they are genuine, clearly described, and not misleading. This protects professionals who spend Tracecoins to send requests.

7-day expiry:
Requirements that remain open without reaching 10 acceptances will automatically expire after 7 days. You will receive a reminder email 1 day before expiry. If you still need the service, you can post a new requirement.

What happens to pending requests on expiry:
If professionals have sent requests that were neither accepted nor rejected when the requirement expires, their reserved Tracecoins are automatically returned to them.',
  ARRAY['CUSTOMER'],
  ARRAY['requirements', 'expiry', 'approval', 'lifecycle'],
  true
) ON CONFLICT (slug) DO NOTHING;

-- ── For Professionals ─────────────────────────────────────────────────────────

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_professionals,
  'Professional onboarding guide',
  'professional-onboarding-guide',
  'Set up your professional profile, upload portfolio, and get verified.',
  'Nxtgauge supports 9 professional categories: Photographer, Makeup Artist, Tutor, Developer, Video Editor, Graphic Designer, Social Media Manager, Fitness Trainer, and Catering Service. Each has its own onboarding form.

What to prepare:
- Government-issued photo ID
- Proof of experience or qualification (degree, certificate, or work samples)
- Portfolio images or links (at least 3 samples recommended)
- A professional bio and list of services you offer

Steps:
1. After registration, select your profession type.
2. Fill in the profession-specific onboarding form. This includes your specialisation, years of experience, tools or techniques you use, and your service area.
3. Add your portfolio items and services.
4. Upload your identity and qualification documents.
5. Submit for review.

After submission:
Your profile enters the admin review queue. Reviews typically take 1–3 business days. Once approved, your profile appears on the marketplace and you can start browsing customer requirements and sending lead requests.

Your dashboard will show a "Pending Verification" banner until approval. During this time you can set up your portfolio and services but cannot send lead requests.',
  ARRAY['PHOTOGRAPHER', 'MAKEUP_ARTIST', 'TUTOR', 'DEVELOPER', 'VIDEO_EDITOR', 'GRAPHIC_DESIGNER', 'SOCIAL_MEDIA_MANAGER', 'FITNESS_TRAINER', 'CATERING_SERVICES'],
  ARRAY['professional', 'onboarding', 'portfolio', 'verification'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_professionals,
  'How the marketplace works',
  'how-the-marketplace-works',
  'Discover how customer requirements appear in your marketplace feed.',
  'The marketplace is where you find customers who need your services. It is powered by live, approved requirements that customers have posted.

What you see in the marketplace:
- Requirements filtered to your profession type (e.g., a photographer only sees photography requirements).
- Each listing shows: requirement title, customer location, budget range, preferred date, and how many professionals have already been accepted (X/10).
- Requirements are sorted by most recent first.

Filters available:
- Location
- Budget range
- Date range
- Keyword search

What the numbers mean:
- "5 requested, 3 accepted" — 5 professionals have sent requests, 3 have been accepted by the customer. Once 10 are accepted, the requirement closes.

Finding the right requirements:
Read the description carefully before sending a request. A good match means the customer is more likely to accept your request, and you do not waste Tracecoins on unsuitable requirements.

Marketplace availability:
The marketplace is only accessible after your profile is approved. Requirements that are expired, closed, or from other profession categories are not shown.',
  ARRAY['PHOTOGRAPHER', 'MAKEUP_ARTIST', 'TUTOR', 'DEVELOPER', 'VIDEO_EDITOR', 'GRAPHIC_DESIGNER', 'SOCIAL_MEDIA_MANAGER', 'FITNESS_TRAINER', 'CATERING_SERVICES'],
  ARRAY['marketplace', 'leads', 'requirements', 'professional'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_professionals,
  'How to send a lead request',
  'how-to-send-a-lead-request',
  'Request to connect with a customer and understand how Tracecoins are reserved.',
  'When you find a requirement you want to pursue, you send a lead request to the customer.

How to send a request:
1. Open the requirement from your marketplace.
2. Review the details carefully.
3. Click "Send Request".
4. Confirm — 25 Tracecoins are reserved from your wallet.

What "reserved" means:
The 25 Tracecoins are not immediately deducted. They are held in reserve while the customer reviews your request. This protects you from losing Tracecoins if the customer never responds.

When Tracecoins are deducted (burned):
- The customer accepts your request. 25 Tracecoins are permanently deducted at this point.

When Tracecoins are returned:
- The customer rejects your request.
- The requirement expires before the customer responds.
- You cancel your request (only possible while still pending).

Rate limits:
- You can send a maximum of 5 lead requests per hour to prevent spam.
- Each requirement has a maximum of 20 requests from professionals. If the cap is reached, the button is disabled.

Requirements for sending a request:
- Your profile must be approved.
- You must have at least 25 Tracecoins available (not just in wallet — actually available after accounting for reserves).
- You have not already sent a request for the same requirement.',
  ARRAY['PHOTOGRAPHER', 'MAKEUP_ARTIST', 'TUTOR', 'DEVELOPER', 'VIDEO_EDITOR', 'GRAPHIC_DESIGNER', 'SOCIAL_MEDIA_MANAGER', 'FITNESS_TRAINER', 'CATERING_SERVICES'],
  ARRAY['leads', 'request', 'tracecoins', 'marketplace'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_professionals,
  'Managing your portfolio and services',
  'managing-portfolio-and-services',
  'Add, edit, and delete portfolio items and service offerings from your dashboard.',
  'Your portfolio and services are visible to customers when they review your profile after you send a lead request.

Portfolio:
A portfolio item is a sample of your past work. Add at least 3–5 strong items to make a good impression.

To add a portfolio item:
1. Go to Dashboard → Portfolio.
2. Click "Add Item".
3. Upload an image and fill in the title, description, and any relevant tags.
4. Click Save.

You can edit or delete any item at any time. Changes are reflected immediately.

Services:
Services list what you offer and at what price. They help customers understand what they can hire you for.

To add a service:
1. Go to Dashboard → Services.
2. Click "Add Service".
3. Enter the service name, description, price (INR), and duration.
4. Click Save.

Keeping your profile fresh:
Regularly update your portfolio with recent work. Customers tend to engage more with profiles that show recent, high-quality samples. Services should reflect your current pricing and availability.',
  ARRAY['PHOTOGRAPHER', 'MAKEUP_ARTIST', 'TUTOR', 'DEVELOPER', 'VIDEO_EDITOR', 'GRAPHIC_DESIGNER', 'SOCIAL_MEDIA_MANAGER', 'FITNESS_TRAINER', 'CATERING_SERVICES'],
  ARRAY['portfolio', 'services', 'profile', 'professional'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_professionals,
  'Lead request expiry explained',
  'lead-request-expiry',
  'What happens to your lead request if a customer does not respond within 24 hours.',
  'Once you send a lead request, the customer has 24 hours to accept or reject it. This window exists to ensure you are not left waiting indefinitely with Tracecoins in reserve.

What happens at expiry:
- If the customer has not responded within 24 hours, your request automatically expires.
- Your 25 reserved Tracecoins are immediately returned to your available balance.
- The request shows as "Expired" in your Requests list.

Can I cancel a request before it expires?
Yes. Go to Dashboard → My Requests, find the pending request, and click Cancel. Your Tracecoins are returned immediately.

What if the customer was just slow?
If your request expired but you are still interested, you can send a new request to the same requirement (if it is still open and you have available Tracecoins). The 25 Tracecoins will be reserved again.

Tracking your requests:
Dashboard → My Requests shows all requests in real time: Pending, Accepted, Rejected, and Expired. Filter by status to quickly find what needs attention.',
  ARRAY['PHOTOGRAPHER', 'MAKEUP_ARTIST', 'TUTOR', 'DEVELOPER', 'VIDEO_EDITOR', 'GRAPHIC_DESIGNER', 'SOCIAL_MEDIA_MANAGER', 'FITNESS_TRAINER', 'CATERING_SERVICES'],
  ARRAY['leads', 'expiry', 'tracecoins', 'requests'],
  true
) ON CONFLICT (slug) DO NOTHING;

-- ── Tracecoins & Billing ──────────────────────────────────────────────────────

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_tracecoins,
  'What are Tracecoins?',
  'what-are-tracecoins',
  'The internal currency of Nxtgauge and what you can use it for.',
  'Tracecoins are the internal currency of the Nxtgauge platform. They are purchased with Indian Rupees via Razorpay and used to unlock platform actions.

Who uses Tracecoins?
- Professionals use Tracecoins to send lead requests to customers (25 coins per request, reserved on send, deducted on acceptance).
- Companies use Tracecoins to purchase additional job posting slots and candidate contact view packages.

Why does this system exist?
The Tracecoin system ensures that both professionals and companies are genuinely interested in the actions they take. A professional who reserves 25 Tracecoins to request a lead has real skin in the game. This results in higher quality engagement for customers and a better signal-to-noise ratio across the platform.

Are Tracecoins refundable?
Tracecoins can be returned to your balance (but not converted back to INR) in specific cases:
- A professional''s lead request is rejected by the customer.
- A requirement expires before the customer responds.
- A professional cancels their own request.

Purchased Tracecoins do not expire and are not transferable between accounts.',
  '{}',
  ARRAY['tracecoins', 'currency', 'billing', 'leads'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_tracecoins,
  'How to buy Tracecoins',
  'how-to-buy-tracecoins',
  'Purchase Tracecoins via Razorpay to unlock platform actions.',
  'Tracecoins can be purchased from within the platform using Razorpay, India''s leading payment gateway.

Steps to buy Tracecoins:
1. Go to Dashboard → Wallet → Buy Tracecoins.
2. Choose a package. Packages are listed with their Tracecoin amount and INR price. Larger packages offer better value.
3. Click "Buy Now". A Razorpay payment modal appears.
4. Complete payment using UPI, net banking, debit card, or credit card.
5. On successful payment, Tracecoins are credited to your wallet instantly.
6. A GST-compliant invoice is emailed to your registered address and also available in Dashboard → Wallet → Invoices.

Packages:
Available packages are set by the Nxtgauge team and may change. Always check the Packages page for current pricing.

Payment security:
All transactions are processed by Razorpay and are fully encrypted. Nxtgauge does not store your card or UPI details.

What if my payment succeeded but Tracecoins were not credited?
Wait 5 minutes, then refresh your wallet. If the issue persists, contact support@nxtgauge.com with your Razorpay transaction ID.',
  '{}',
  ARRAY['tracecoins', 'buy', 'razorpay', 'payment', 'billing'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_tracecoins,
  'Understanding your Tracecoin wallet and ledger',
  'tracecoin-wallet-and-ledger',
  'Read your wallet balance, understand reserved vs available coins, and browse your transaction ledger.',
  'Your Tracecoin wallet is the central hub for tracking your balance and history.

Wallet overview:
- Total balance: All Tracecoins you own.
- Reserved: Tracecoins currently held in reserve for pending lead requests. They are not yet permanently spent.
- Available: Total balance minus reserved. This is what you can spend on new actions.

Reading the ledger:
The ledger is a complete, immutable history of every Tracecoin transaction on your account. Go to Dashboard → Wallet → Ledger.

Each ledger entry shows:
- Date and time
- Transaction type (Purchase, Lead Reserved, Lead Deducted, Lead Returned, Admin Credit, etc.)
- Amount (positive for credits, negative for debits)
- Running balance
- Reason or reference

Why is the ledger immutable?
The ledger is append-only for integrity. No entry can be edited or deleted — not even by the admin team. This ensures full transparency and auditability of your Tracecoin history.

Invoices:
Every Razorpay purchase generates a GST-compliant invoice. Go to Dashboard → Wallet → Invoices to download past invoices.',
  ARRAY['PHOTOGRAPHER', 'MAKEUP_ARTIST', 'TUTOR', 'DEVELOPER', 'VIDEO_EDITOR', 'GRAPHIC_DESIGNER', 'SOCIAL_MEDIA_MANAGER', 'FITNESS_TRAINER', 'CATERING_SERVICES'],
  ARRAY['wallet', 'ledger', 'tracecoins', 'balance', 'invoices'],
  true
) ON CONFLICT (slug) DO NOTHING;

-- ── Platform Policies ─────────────────────────────────────────────────────────

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_policies,
  'Content approval policy',
  'content-approval-policy',
  'Why all jobs and requirements go through an approval review before going live.',
  'All user-generated content that reaches other users — specifically job postings and service requirements — must pass an admin review before going live. This is a core part of how Nxtgauge maintains platform quality.

What is reviewed:
- Job postings: Title accuracy, description clarity, compensation honesty, no discriminatory language.
- Service requirements: Clarity of the service needed, realistic budget, appropriate category selection.

Turnaround time:
Reviews are completed within 1 business day in most cases. You will receive an email as soon as a decision is made.

Consequences of policy violation:
Listings that violate platform policies will be rejected. Repeated violations may result in restrictions on your account''s ability to post new listings. Severe violations (fraud, impersonation, discriminatory content) may result in account suspension.

Appealing a rejection:
If you believe your listing was incorrectly rejected, contact support@nxtgauge.com with your listing ID and the reason you believe it should be approved. The team will review your appeal within 2 business days.',
  '{}',
  ARRAY['policy', 'approval', 'content', 'jobs', 'requirements'],
  true
) ON CONFLICT (slug) DO NOTHING;

INSERT INTO kb_articles (category_id, title, slug, summary, body, target_roles, tags, is_published) VALUES (
  cat_policies,
  'Account suspension and bans',
  'account-suspension-and-bans',
  'What actions can lead to account suspension and how to appeal.',
  'Nxtgauge takes platform integrity seriously. Accounts that violate our terms of service may be suspended or permanently banned.

Actions that can lead to suspension:
- Submitting false or misleading verification documents.
- Posting fraudulent job listings (e.g., fake jobs designed to collect candidate data).
- Spamming lead requests or requirements.
- Harassing other users.
- Attempting to circumvent the Tracecoin system or approval process.
- Creating multiple accounts for the same person or business.

Suspension vs Ban:
- Suspension: Temporary. Your account is restricted for a period. You will receive an email explaining the reason and duration. At the end of the period, access is restored if no further violations occur.
- Ban: Permanent. Your account is disabled and you may not create new accounts on Nxtgauge.

What to do if your account is suspended:
1. Read the suspension email carefully to understand the reason.
2. If you believe the suspension was in error, contact support@nxtgauge.com with your full name, email address, and a clear explanation.
3. Appeals are reviewed within 5 business days.

Prevention:
The best way to avoid account issues is to read and follow the platform guidelines, submit genuine documents, and engage with other users respectfully.',
  '{}',
  ARRAY['policy', 'suspension', 'ban', 'account', 'terms'],
  true
) ON CONFLICT (slug) DO NOTHING;

RAISE NOTICE 'KB seed complete — 8 categories, 28 articles inserted.';
END $$;
