<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class ClcSeedDefaultEvaluationQuestions extends Migration
{
    public function up()
    {
        $now = now();

        // Pet owner evaluation (filled by doctor)
        $patientContact = [
            ['How cooperative was the pet owner during the visit?',          'rating', 10],
            ['How well did the owner follow previous instructions?',          'rating', 20],
            ['How attentive was the owner to the pet\'s condition?',          'rating', 30],
            ['Did the owner provide a complete medical history?',             'yes_no', 40],
            ['Owner\'s overall responsibility level',                         'rating', 50],
            ['Additional notes about the owner',                              'text',   60],
        ];

        foreach ($patientContact as [$text, $type, $sort]) {
            DB::table('clc_evaluation_questions')->updateOrInsert(
                ['business_id' => null, 'category' => 'pet_owner', 'question_text' => $text],
                [
                    'response_type' => $type,
                    'is_required'   => $type !== 'text',
                    'sort_order'    => $sort,
                    'status'        => 'active',
                    'created_at'    => $now,
                    'updated_at'    => $now,
                ]
            );
        }

        // Clinic / doctor evaluation (filled by receptionist on behalf of pet owner)
        $clinic = [
            ['How would you rate the doctor\'s communication?',              'rating', 10],
            ['How would you rate the quality of medical care?',               'rating', 20],
            ['How would you rate the cleanliness of the clinic?',             'rating', 30],
            ['How would you rate the reception / staff service?',             'rating', 40],
            ['How would you rate the wait time?',                             'rating', 50],
            ['Overall satisfaction with the visit',                           'rating', 60],
            ['Would you recommend our clinic to others?',                     'yes_no', 70],
            ['Any suggestions or comments',                                   'text',   80],
        ];

        foreach ($clinic as [$text, $type, $sort]) {
            DB::table('clc_evaluation_questions')->updateOrInsert(
                ['business_id' => null, 'category' => 'clinic', 'question_text' => $text],
                [
                    'response_type' => $type,
                    'is_required'   => $type !== 'text',
                    'sort_order'    => $sort,
                    'status'        => 'active',
                    'created_at'    => $now,
                    'updated_at'    => $now,
                ]
            );
        }
    }

    public function down()
    {
        DB::table('clc_evaluation_questions')->whereNull('business_id')->delete();
    }
}
