<?php

use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;


return new class extends Migration
{
    public function up(): void
    {
        $segments = Segment::listActive();
        foreach ($segments as $segment) {
            Schema::connection($segment->connector)->create('pipi_owner_contracts', static function (Blueprint $table) {
                $table->id();
                $table->boolean('is_group')->default(false)->comment('Это группа');
                $table->string('code')->nullable()->comment('Код');
                $table->string('name')->nullable()->comment('Наименование');
                $table->string('comments')->nullable()->comment('Комментарий');
                $table->string('organization')->nullable()->comment('Организация');
                $table->string('contract_number')->nullable()->comment('Номер договора');
                $table->date('contract_date')->nullable()->comment('Дата договора');
                $table->date('started_at')->nullable()->comment('Дата начала действия');
                $table->date('ended_at')->nullable()->comment('Дата окончания');
                $table->string('payment_type')->nullable()->comment('Условия оплаты');

                $table->timestamps();
                $table->softDeletes();

                $table->unsignedBigInteger('parent_id');
                $table->foreign('parent_id')->references('id')->on('pipi_owner_contracts');
            });
        }
    }
};
