<?php

namespace Database\Seeders;

use App\Models\Corporate;
use App\Models\Service;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class ServiceSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $services = [
            [
                'id' => 1,
                'name' => 'Outpatient',
                'code' => 'OP',
                'description' => 'Outpatient',
            ],
            [
                'id' => 2,
                'name' => 'Inpatient',
                'code' => 'IP',
                'description' => 'Inpatient',
            ],
            [
                'id' => 3,
                'name' => 'Dental',
                'code' => 'DE',
                'description' => 'Dental',
            ],
            [
                'id' => 4,
                'name' => 'Maternal',
                'code' => 'MA',
                'description' => 'Maternal',
            ],
            [
                'id' => 5,
                'name' => 'Optical',
                'code' => 'OPT',
                'description' => 'Optical',
            ],
            [
                'id' => 6,
                'name' => 'Medical Check Up',
                'code' => 'MCU',
                'description' => 'Medical Check Up',
            ],
        ];


        $corporates = Corporate::get();

        foreach ($services as $service) {
            $service = Service::updateOrCreate(['id' => $service['id']], $service);

            foreach ($corporates as $corporate) {
                $corporateService = $corporate->corporateServices()->firstOrCreate([
                    'service_code' => $service->code
                ],[
                    'service_code' => $service->code,
                    'status' => 'inactive'
                ]);

                $corporate_service_configs_data = [
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'gp_external_doctor_online',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'gp_external_doctor_offline',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'gp_internal_doctor_online',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'gp_internal_doctor_offline',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'sp_external_doctor_online',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'sp_external_doctor_offline',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'sp_internal_doctor_online',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'sp_internal_doctor_offline',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'vitamins',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'delivery_fee',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'general_practitioner_fee',
                        'value' => false,
                    ],
                    [
                        'corporate_service_id' => $corporateService->id,
                        'name' => 'specialist_practitioner_fee',
                        'value' => false,
                    ],
                ];

                foreach ($corporate_service_configs_data as $config) {
                    $corporateService->configs()->firstOrCreate([
                        'corporate_service_id' => $config['corporate_service_id'],
                        'name' => $config['name']
                    ], $config);
                }
            }
        }
    }
}
