<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Employee;
use App\Models\Lead;
use App\Models\LeadNote;
use Carbon\Carbon;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        // ── EMPLOYEES ──────────────────────────────────
        $employees = [
            ['emp_id'=>'EMP001','name'=>'Suresh B.','role'=>'Sales Executive','department'=>'Sales','phone'=>'+91 98765 43210','email'=>'suresh@royalitpark.com','status'=>'Active','join_date'=>'2022-03-15','target'=>25,'avatar_color'=>'#1a73e8','notes'=>'Top performer. Handles enterprise clients.'],
            ['emp_id'=>'EMP002','name'=>'Anita R.','role'=>'Sales Manager','department'=>'Management','phone'=>'+91 98765 43211','email'=>'anita@royalitpark.com','status'=>'Active','join_date'=>'2021-01-10','target'=>30,'avatar_color'=>'#059669','notes'=>'Team lead for Hyderabad zone.'],
            ['emp_id'=>'EMP003','name'=>'Rahul K.','role'=>'Digital Marketing Exec.','department'=>'Marketing','phone'=>'+91 98765 43212','email'=>'rahul@royalitpark.com','status'=>'Active','join_date'=>'2023-06-01','target'=>20,'avatar_color'=>'#7c3aed','notes'=>'Handles SEO and social media leads.'],
            ['emp_id'=>'EMP004','name'=>'Meena K.','role'=>'Support Executive','department'=>'Support','phone'=>'+91 98765 43213','email'=>'meena@royalitpark.com','status'=>'Active','join_date'=>'2022-11-20','target'=>15,'avatar_color'=>'#d97706','notes'=>'Post-sales and customer support.'],
            ['emp_id'=>'EMP005','name'=>'Ravi T.','role'=>'Technical Sales','department'=>'Technical','phone'=>'+91 98765 43214','email'=>'ravi@royalitpark.com','status'=>'Active','join_date'=>'2023-02-14','target'=>18,'avatar_color'=>'#dc2626','notes'=>'Handles technical demos and proposals.'],
        ];
        foreach ($employees as $e) {
            Employee::create($e);
        }

        $emp = Employee::pluck('id', 'name'); // name => id map

        // ── LEADS ──────────────────────────────────────
        $leads = [
            ['name'=>'Rajesh Kumar','company'=>'TechWave Solutions','phone'=>'9876543210','email'=>'rajesh@techwave.in','source'=>'Website','service'=>'Website + SEO','budget'=>125000,'stage'=>'Positive','assigned_to'=>$emp['Suresh B.'],'priority'=>'High','last_contact'=>'2026-06-20'],
            ['name'=>'Priya Sharma','company'=>'Startup Labs','phone'=>'9123456789','email'=>'priya@startuplabs.io','source'=>'Referral','service'=>'Website Design','budget'=>60000,'stage'=>'Follow Up','assigned_to'=>$emp['Anita R.'],'priority'=>'Medium','last_contact'=>'2026-06-18'],
            ['name'=>'Ananya Mehta','company'=>'Digital Peak','phone'=>'9000012345','email'=>'ananya@digitalpeak.in','source'=>'WhatsApp','service'=>'SEO Package','budget'=>42000,'stage'=>'Negotiation','assigned_to'=>$emp['Suresh B.'],'priority'=>'High','last_contact'=>'2026-06-19'],
            ['name'=>'Kiran Reddy','company'=>'BuildFast Infra','phone'=>'9988776655','email'=>'kiran@buildfast.in','source'=>'Phone Call','service'=>'App Development','budget'=>280000,'stage'=>'Contacted','assigned_to'=>$emp['Rahul K.'],'priority'=>'High','last_contact'=>'2026-06-21'],
            ['name'=>'Meghna Iyer','company'=>'FreshBrew Co','phone'=>'9871234567','email'=>'meghna@freshbrew.in','source'=>'WhatsApp','service'=>'Digital Marketing','budget'=>35000,'stage'=>'New','assigned_to'=>$emp['Meena K.'],'priority'=>'Low','last_contact'=>'2026-06-22'],
            ['name'=>'Sanjay Verma','company'=>'Skyline Ventures','phone'=>'9123409876','email'=>'sanjay@skyline.vc','source'=>'Email','service'=>'Website + SEO','budget'=>90000,'stage'=>'Follow Up','assigned_to'=>$emp['Ravi T.'],'priority'=>'Medium','last_contact'=>'2026-06-16'],
            ['name'=>'Arjun Nair','company'=>'Nexus Tech','phone'=>'9823456780','email'=>'arjun@nexustech.in','source'=>'Referral','service'=>'Website Design','budget'=>75000,'stage'=>'Won','assigned_to'=>$emp['Anita R.'],'priority'=>'High','last_contact'=>'2026-06-12'],
            ['name'=>'Divya Krishnan','company'=>'BloomHR','phone'=>'9012345678','email'=>'divya@bloomhr.co','source'=>'Website','service'=>'SEO Package','budget'=>28000,'stage'=>'Lost','assigned_to'=>$emp['Meena K.'],'priority'=>'Low','last_contact'=>'2026-06-08'],
        ];
        foreach ($leads as $l) {
            Lead::create($l);
        }

        // ── NOTES ──────────────────────────────────────
        $notes = [
            // Lead 1 – Rajesh Kumar
            [1,'Suresh B.','#1a73e8','Phone Call','Budget confirmed Rs1.25L. Proposal requested by Wednesday.'],
            [1,'Suresh B.','#1a73e8','Email','Sent portfolio and 3 case studies. Replied within 2 hours.'],
            // Lead 2 – Priya Sharma
            [2,'Anita R.','#059669','Email','Sent portfolio. She liked the Innovate Hub project. Decision by Friday.'],
            // Lead 3 – Ananya Mehta
            [3,'Suresh B.','#1a73e8','WhatsApp','Wants 6-month SEO. Asking 10% discount. Offered 5% plus free report.'],
            // Lead 4 – Kiran Reddy
            [4,'Rahul K.','#7c3aed','Phone Call','Initial call done. Field staff tracking app needed by September.'],
            // Lead 6 – Sanjay Verma
            [6,'Ravi T.','#dc2626','Email','Sent updated proposal. No reply in 6 days. Budget may stretch to Rs1L.'],
            // Lead 7 – Arjun Nair
            [7,'Anita R.','#059669','Meeting','Deal closed! Rs75,000. 50% advance received. Work starts Monday!'],
            // Lead 8 – Divya Krishnan
            [8,'Meena K.','#d97706','Phone Call','Client went with cheaper option. Will revisit in Q4 2026.'],
        ];
        foreach ($notes as [$lid,$by,$col,$via,$note]) {
            LeadNote::create(['lead_id'=>$lid,'added_by'=>$by,'avatar_color'=>$col,'via'=>$via,'note'=>$note]);
        }
    }
}