<?php

namespace Database\Seeders;

use App\Models\Practice;
use App\Models\PractitionerRole;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class PractitionerRoleDummySeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Practice::truncate();

        $times = [
            '07:00:00',
            '07:30:00',
            '08:00:00',
            '08:30:00',
            '09:00:00',
            '09:30:00',
            '10:00:00',
            '10:30:00',
            '11:00:00',
            '11:30:00',
            '12:00:00',
            '12:30:00',
            '13:00:00',
            '13:30:00',
            '14:00:00',
            '14:30:00',
            '15:00:00',
            '15:30:00',
            '16:00:00',
            '16:30:00',
            '17:00:00',
            '17:30:00',
            '18:00:00',
            '18:30:00',
        ];

        PractitionerRole::chunk(100, function($chunkedPractitionerRoles) use ($times)  {
            foreach ($chunkedPractitionerRoles as $practitionerRole) {
                $practitionerRole->practices()->insert([
                    [
                        'practitioner_role_id' => $practitionerRole->id,
                        'service_code' => 'instant-chat',
                        'active' => 1,
                    ],
                    [
                        'practitioner_role_id' => $practitionerRole->id,
                        'service_code' => 'chat',
                        'active' => 1,
                    ],
                    [
                        'practitioner_role_id' => $practitionerRole->id,
                        'service_code' => 'video',
                        'active' => 1,
                    ],
                    [
                        'practitioner_role_id' => $practitionerRole->id,
                        'service_code' => 'walkin',
                        'active' => 1,
                    ],
                ]);

                $availabilities_data = [];
                foreach($times as $time) {
                    $availabilities_data[] = [
                        'practitioner_role_id' => $practitionerRole->id,
                        'all_day' => 0,
                        'start_time' => $time
                    ];
                }

                $practitionerRole->availabilities()->insert($availabilities_data);
            }
        });
    }
}
