<?php

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

/**
 * Seed system-default treatment-package templates (business_id NULL → visible to
 * every clinic). Dermatology/aesthetic-oriented; clinics can add their own and
 * set their own pricing from the Packages settings screen.
 */
class SeedClcTreatmentPackages extends Migration
{
    public function up()
    {
        if (!Schema::hasTable('clc_treatment_packages')) return;
        $now = now();

        $packages = [
            ['Laser Hair Removal — Course',      6, 28, 'Full course of laser hair-removal sessions.'],
            ['Chemical Peel Course',             4, 21, 'Series of superficial chemical peels.'],
            ['Microneedling (Collagen Induction)',3, 30, 'Collagen-induction therapy series.'],
            ['Acne Treatment Program',           6, 14, 'Structured acne management with review.'],
            ['PRP Hair Restoration',             4, 30, 'Platelet-rich plasma scalp injections.'],
            ['Hydrafacial Series',               3, 30, 'Hydradermabrasion facial series.'],
            ['Phototherapy (Narrowband UVB)',   12,  3, 'Narrowband UVB phototherapy course.'],
        ];

        $sort = 0;
        foreach ($packages as [$name, $sessions, $interval, $desc]) {
            $exists = DB::table('clc_treatment_packages')
                ->whereNull('business_id')->where('name', $name)->exists();
            if ($exists) continue;
            DB::table('clc_treatment_packages')->insert([
                'business_id'    => null,
                'specialty_id'   => null,
                'name'           => $name,
                'description'    => $desc,
                'total_sessions' => $sessions,
                'interval_days'  => $interval,
                'price'          => null,
                'is_active'      => true,
                'sort_order'     => $sort++,
                'created_at'     => $now,
                'updated_at'     => $now,
            ]);
        }
    }

    public function down()
    {
        if (!Schema::hasTable('clc_treatment_packages')) return;
        DB::table('clc_treatment_packages')->whereNull('business_id')->delete();
    }
}
