﻿<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        $now = now();

        foreach ($this->templates() as $identifier => $data) {
            if (DB::table('sms_templates')->where('identifier', $identifier)->exists()) {
                continue;
            }

            DB::table('sms_templates')->insert(array_merge($data, [
                'identifier' => $identifier,
                'created_at' => $now,
                'updated_at' => $now,
            ]));
        }
    }

    private function templates(): array
    {
        return [
            'pos_order_placement' => [
                'name' => 'POS Order Placement',
                'body' => 'Thanks for your purchase, [[customer_name]]! Your order is processed. View details here: [[invoice_link]]. - Kiyo',
                'template_id' => 1707172352407012545,
                'is_active' => true,
            ],
            'order_tracking_details' => [
                'name' => 'Order Tracking Details',
                'body' => "We're excited to know your order: [[order_id]] has been shipped! Track your shipment here: [[orders_url]]. - Kiyo",
                'template_id' => 1707172465830021262,
                'is_active' => true,
            ],
        ];
    }

    public function down(): void
    {
        DB::table('sms_templates')->whereIn('identifier', [
            'pos_order_placement',
            'order_tracking_details',
        ])->delete();
    }
};
