<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
		Schema::create('supplier_ssl',function (Blueprint $table)
		{
			$table->id();
			$table->timestamps();
			$table->integer('site_id')->unsigned();
			$table->boolean('active')->default(false);

			$table->string('product_id',16);
			$table->string('product_desc',128)->nullable();
			$table->float('base_cost');
			$table->float('setup_cost')->nullable();
			$table->integer('contract_term')->unsigned()->nullable();

			$table->integer('supplier_detail_id')->unsigned();
			$table->foreign(['supplier_detail_id','site_id'])->references(['id','site_id'])->on('supplier_details');

			$table->unique(['id','site_id']);
		});

		Schema::create('product_ssl',function (Blueprint $table)
		{
			$table->id();
			$table->timestamps();
			$table->integer('site_id')->unsigned();
			$table->boolean('active')->default(false);

			$table->string('name',64);
			$table->integer('contract_term')->unsigned()->nullable();

			$table->integer('supplier_item_id')->unsigned();
			$table->foreign(['supplier_item_id','site_id'])->references(['id','site_id'])->on('supplier_ssl');

			$table->unique(['id','site_id']);
		});

		Schema::create('service_ssl', function(Blueprint $table)
		{
			$table->id();
			$table->timestamps();
			$table->integer('site_id')->unsigned();

			$table->integer('ssl_ca_id')->unsigned()->nullable();
			$table->text('csr');
			$table->text('pk')->nullable();
			$table->text('cert')->nullable();

			$table->integer('service_id')->unsigned();
			$table->foreign(['service_id','site_id'])->references(['id','site_id'])->on('services');

			$table->unique(['id','site_id']);
		});
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
		Schema::dropIfExists('service_ssl');
        Schema::dropIfExists('product_ssl');
		Schema::dropIfExists('supplier_ssl');
    }
};