<?php

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

class UpdateDatabaseStructure extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		/*
		// ========== Drop Tables ==========
		// Xóa các bảng pivot trước
		Schema::dropIfExists('product_accessories');
		Schema::dropIfExists('product_scenes');
		Schema::dropIfExists('product_colors');
		Schema::dropIfExists('product_categories');
		Schema::dropIfExists('product_schedules');
		Schema::dropIfExists('product_images');
		
		// Xóa các bảng liên quan đến order
		Schema::dropIfExists('order_details');
		Schema::dropIfExists('orders');
		Schema::dropIfExists('incomes');
		Schema::dropIfExists('withdrawals');
		Schema::dropIfExists('payments');
		
		// Xóa các bảng liên quan đến user
		Schema::dropIfExists('user_delivery_addresses');
		Schema::dropIfExists('user_face_swaps');
		Schema::dropIfExists('user_cards');
		Schema::dropIfExists('template_attachments');
		Schema::dropIfExists('templates');
		
		// Xóa các bảng chính
		Schema::dropIfExists('products');
		Schema::dropIfExists('accessories');
		Schema::dropIfExists('scenes');
		Schema::dropIfExists('colors');
		Schema::dropIfExists('categories');
		Schema::dropIfExists('users');
		
		
		// ========== Create Tables Group 1 ==========
		// Category
		Schema::create('categories', function (Blueprint $table) {
			$table->id();
			$table->string('name');
			$table->string('slug')->nullable();
			$table->unsignedBigInteger('parent_id')->nullable();
			$table->tinyText('description')->nullable();
			$table->unsignedInteger('position')->default(0);
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraint
			$table->foreign('parent_id')->references('id')->on('categories')->onDelete('restrict')->onUpdate('cascade');
			
			// Indexes
			$table->index('name');
			$table->index('slug');
		});
		
		// Color
		Schema::create('colors', function (Blueprint $table) {
			$table->id();
			$table->string('name');
			$table->string('slug')->nullable();
			$table->string('code')->nullable();
			$table->tinyText('description')->nullable();
			$table->unsignedInteger('position')->default(0);
			$table->timestamps();
			$table->softDeletes();
			
			// Indexes
			$table->index('name');
			$table->index('slug');
			$table->index('code');
		});
		
		// Scene
		Schema::create('scenes', function (Blueprint $table) {
			$table->id();
			$table->string('name');
			$table->string('slug')->nullable();
			$table->unsignedBigInteger('parent_id')->nullable();
			$table->tinyText('description')->nullable();
			$table->unsignedInteger('position')->default(0);
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraint
			$table->foreign('parent_id')->references('id')->on('scenes')->onDelete('restrict')->onUpdate('cascade');
			
			// Indexes
			$table->index('name');
			$table->index('slug');
		});
		
		// Accessory
		Schema::create('accessories', function (Blueprint $table) {
			$table->id();
			$table->string('name');
			$table->string('slug')->nullable();
			$table->string('code')->nullable();
			$table->smallInteger('type')->default(0)->comment('Type: 0-Kimono, 1-Obi, 2-Juban, 3-Obijime, 4-Obiage, 5-Kasaneeri');
			$table->tinyText('description')->nullable();
			$table->unsignedInteger('position')->default(0);
			$table->timestamps();
			$table->softDeletes();
			
			// Indexes
			$table->index('name');
			$table->index('slug');
			$table->index('code');
			$table->index('type');
		});
		
		
		// ========== Create Tables Group 2 ==========
		// User
		Schema::create('users', function (Blueprint $table) {
			$table->id();
			$table->string('code');
			$table->string('name')->nullable();
			$table->string('last_name')->nullable();
			$table->string('first_name')->nullable();
			$table->string('full_name')->nullable();
			$table->string('furigana_last_name')->nullable();
			$table->string('furigana_first_name')->nullable();
			$table->string('furigana_name')->nullable();
			
			$table->string('username')->nullable();
			$table->string('email')->unique();
			$table->string('email2')->nullable();
			$table->timestamp('email_verified_at')->nullable();
			$table->string('verify_code')->nullable();
			$table->unsignedSmallInteger('verify_card')->default(0);
			$table->dateTime('verify_created_at')->nullable();
			$table->smallInteger('email_subscribe')->nullable();
			$table->smallInteger('email_format')->nullable();
			$table->string('password');
			$table->string('remember_token', 100)->nullable();
			
			$table->string('avatar')->nullable();
			$table->string('faceswap')->nullable();
			$table->integer('gender')->default(1);
			$table->string('career')->nullable();
			$table->date('date_of_birth')->nullable();
			
			$table->string('post_code')->nullable();
			$table->string('city')->nullable();
			$table->string('district')->nullable();
			$table->tinyText('address')->nullable();
			$table->tinyText('address2')->nullable();
			
			$table->string('phone_number')->nullable();
			$table->string('fax_number')->nullable();
			$table->string('mobile_tel')->nullable();
			$table->string('emg_tel')->nullable();
			$table->string('company')->nullable();
			
			$table->string('bank_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('bank_code')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('bank_branch_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('bank_branch_code')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('bank_account_type')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('bank_account_number')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('bank_holder_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('pay_jp_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('pay_jp_email')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('pay_jp_phone_number')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('pay_jp_code')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('stripe_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('stripe_email')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('stripe_phone_number')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('stripe_code')->nullable()->comment('Optional for ProfitWithdrawals');
			
			$table->string('driver_license')->nullable();
			$table->string('insurance_card')->nullable();
			$table->string('number_card')->nullable();
			
			$table->decimal('height', 5, 1)->nullable();
			$table->decimal('sleeve', 5, 1)->nullable();
			$table->decimal('hip', 5, 1)->nullable();
			$table->decimal('waist', 5, 1)->nullable();
			$table->tinyText('introduction')->nullable();
			
			$table->dateTime('reset_password_time')->nullable();
			$table->string('reset_password_code')->nullable();
			$table->string('login_url')->nullable();
			$table->string('login_ip')->nullable();
			$table->smallInteger('is_activated')->default(1);
			$table->unsignedBigInteger('created_by')->default(1);
			$table->timestamps();
			$table->softDeletes();
			
			// Indexes
			$table->index('code');
			$table->index('name');
			$table->index('last_name');
			$table->index('first_name');
			$table->index('full_name');
			$table->index('furigana_last_name');
			$table->index('furigana_first_name');
			$table->index('furigana_name');
			$table->index('username');
			$table->index('email');
		});
		
		
		// ========== Create Tables Group 3 ==========
		// Product
		Schema::create('products', function (Blueprint $table) {
			$table->id();
			$table->string('sku')->nullable();
			$table->string('storage_code')->nullable()->comment('Optional for Storage');
			$table->unsignedSmallInteger('type')->default(0)->comment('Type: 0-Rental, 1-Storage');
			
			$table->string('name');
			$table->string('slug')->nullable();
			$table->string('image')->nullable();
			$table->tinyText('description')->nullable();
			
			$table->string('material')->nullable();
			$table->smallInteger('gender')->default(0);
			$table->smallInteger('size')->default(0);
			$table->unsignedSmallInteger('rank')->default(0)->comment('Rank: 0-S, 1-A');
			$table->decimal('dimension_cm', 5, 1)->nullable();
			$table->string('dimension_scale')->nullable();
			$table->decimal('hip', 5, 1)->nullable();
			$table->decimal('height', 5, 1)->nullable();
			$table->decimal('sleeve', 5, 1)->nullable();
			$table->decimal('sleeve_length', 5, 1)->nullable();
			$table->decimal('front_width', 5, 1)->nullable();
			$table->decimal('rear_width', 5, 1)->nullable();
			$table->decimal('undergarment_length', 5, 1)->nullable();
			
			$table->dateTime('storage_start')->nullable()->comment('Optional for Storage');
			$table->dateTime('storage_end')->nullable()->comment('Optional for Storage');
			
			$table->decimal('storage_regular_price', 15, 2)->nullable()->comment('Optional for Storage');
			$table->decimal('storage_discount', 5, 2)->nullable()->comment('Optional for Storage');
			$table->decimal('storage_price', 15, 2)->nullable()->comment('Optional for Storage');
			
			$table->decimal('rental_regular_price', 15, 2)->nullable()->comment('Optional for Rental');
			$table->decimal('rental_discount', 5, 2)->nullable()->comment('Optional for Rental');
			$table->decimal('rental_price', 15, 2)->nullable()->comment('Optional for Rental');
			
			$table->integer('total_views')->default(0);
			$table->string('preview_code')->nullable();
			$table->unsignedBigInteger('owner_id');
			$table->unsignedBigInteger('created_by');
			$table->unsignedBigInteger('updated_by')->nullable();
			$table->unsignedSmallInteger('status')->default(0)->comment('Status: 0-Preparing, 1-Stored, 2-Rented, 3-Maintenance, 4-Returned');
			
			$table->smallInteger('is_allow_faceswap')->default(1);
			$table->smallInteger('is_allow_sharing')->default(0);
			$table->smallInteger('is_cleaning_service')->default(0);
			$table->smallInteger('is_activated')->default(1);
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('owner_id')->references('id')->on('users')->onDelete('restrict');
			$table->foreign('created_by')->references('id')->on('users')->onDelete('restrict');
			$table->foreign('updated_by')->references('id')->on('users')->onDelete('restrict');
			
			// Indexes
			$table->index('sku');
			$table->index('storage_code');
			$table->index('name');
			$table->index('slug');
			$table->index('type');
			$table->index('size');
			$table->index('rank');
			$table->index('status');
			$table->index('is_activated');
		});
		
		// Product Image
		Schema::create('product_images', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('product_id');
			$table->string('name');
			$table->string('file_name');
			$table->integer('position')->default(0);
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('product_id')->references('id')->on('products')->onDelete('restrict');
		});
		
		// Product Category
		Schema::create('product_categories', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('product_id');
			$table->unsignedBigInteger('category_id');
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('product_id')->references('id')->on('products')->onDelete('restrict');
			$table->foreign('category_id')->references('id')->on('categories')->onDelete('restrict');
		});
		
		// Product Color
		Schema::create('product_colors', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('product_id');
			$table->unsignedBigInteger('color_id');
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('product_id')->references('id')->on('products')->onDelete('restrict');
			$table->foreign('color_id')->references('id')->on('colors')->onDelete('restrict');
		});
		
		// Product Scene
		Schema::create('product_scenes', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('product_id');
			$table->unsignedBigInteger('scene_id');
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('product_id')->references('id')->on('products')->onDelete('restrict');
			$table->foreign('scene_id')->references('id')->on('scenes')->onDelete('restrict');
		});
		
		// Product Accessory
		Schema::create('product_accessories', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('product_id');
			$table->unsignedBigInteger('accessory_id');
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('product_id')->references('id')->on('products')->onDelete('restrict');
			$table->foreign('accessory_id')->references('id')->on('accessories')->onDelete('restrict');
		});
		
		
		// ========== Create Tables Group 4 ==========
		// User Card
		Schema::create('user_cards', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('user_id');
			$table->string('card_id')->nullable();
			$table->string('card_number')->nullable();
			$table->string('card_name')->nullable();
			$table->string('card_brand')->nullable();
			$table->string('card_brand_logo')->nullable();
			$table->string('card_exp_month')->nullable();
			$table->string('card_exp_year')->nullable();
			$table->string('card_last_four')->nullable();
			$table->string('card_fingerprint')->nullable();
			$table->string('card_funding')->nullable();
			$table->smallInteger('is_default')->default(0);
			$table->smallInteger('is_activated')->default(1);
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('user_id')->references('id')->on('users')->onDelete('restrict');
		});
		
		// User Delivery Address
		Schema::create('user_delivery_addresses', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('user_id')->nullable();
			$table->string('first_name');
			$table->string('last_name');
			$table->string('furigana_first_name');
			$table->string('furigana_last_name');
			$table->string('post_code');
			$table->string('city')->nullable();
			$table->string('district')->nullable();
			$table->string('address');
			$table->string('phone_number');
			$table->string('email')->nullable();
			$table->string('company')->nullable();
			$table->smallInteger('is_default')->default(0);
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
		});
		
		// User Face Swap
		Schema::create('user_face_swaps', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('user_id');
			$table->unsignedBigInteger('product_id');
			$table->string('image_source_name')->nullable();
			$table->string('image_target_name')->nullable();
			$table->string('image_result_name')->nullable();
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('user_id')->references('id')->on('users')->onDelete('restrict');
			$table->foreign('product_id')->references('id')->on('products')->onDelete('restrict');
		});
		
		
		// ========== Create Tables Group 5 ==========
		// Order
		Schema::create('orders', function (Blueprint $table) {
			$table->id();
			$table->string('code')->nullable();
			$table->unsignedBigInteger('user_id');
			$table->unsignedBigInteger('user_delivery_address_id')->nullable();
			$table->string('name')->nullable();
			$table->string('first_name')->nullable();
			$table->string('last_name')->nullable();
			$table->string('furigana_first_name')->nullable();
			$table->string('furigana_last_name')->nullable();
			$table->string('furigana_name')->nullable();
			$table->string('phone_number')->nullable();
			$table->string('post_code')->nullable();
			$table->string('city')->nullable();
			$table->string('district')->nullable();
			$table->string('address')->nullable();
			$table->string('email')->nullable();
			$table->string('company')->nullable();
			$table->decimal('total_price', 15, 2)->default(0);
			$table->dateTime('estimated_delivery_date')->nullable();
			$table->smallInteger('payment_method')->default(1)->comment('Payment method: 1-Card, 2-Bank transfer, 3-Cash on delivery');
			$table->smallInteger('payment_status')->default(0)->comment('Payment status: 0-Unpaid, 1-Paid, 2-Refunded');
			$table->tinyText('note')->nullable();
			$table->smallInteger('status')->default(0)->comment('Status: 0-Received, 1-Confirmed, 2-Shipped, 3-Rented, 4-Returned, 5-Completed');
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('user_id')->references('id')->on('users')->onDelete('restrict');
		});
		
		// Order Detail
		Schema::create('order_details', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('order_id')->nullable();
			$table->unsignedBigInteger('product_id')->nullable();
			$table->string('product_name')->nullable();
			$table->string('product_image')->nullable();
			$table->decimal('regular_price', 15, 2)->nullable()->comment('Optional for Rental');
			$table->decimal('discount', 5, 2)->nullable()->comment('Optional for Rental');
			$table->decimal('price', 15, 2)->nullable()->comment('Optional for Rental');
			$table->decimal('tax', 15, 2)->nullable();
			$table->decimal('shipping_cost', 15, 2)->nullable();
			$table->date('shipping_date')->nullable();
			$table->date('wear_date')->nullable();
			$table->string('height')->nullable();
			$table->string('hip')->nullable();
			$table->string('foot')->nullable();
			$table->decimal('safe_pack', 15, 2)->nullable();
			$table->decimal('tabi', 15, 2)->nullable();
			$table->decimal('towel', 15, 2)->nullable();
			$table->string('free_options')->nullable();
			$table->unsignedSmallInteger('quantity')->default(1);
			$table->decimal('total_price', 15, 2)->nullable();
			$table->smallInteger('status')->default(0)->comment('Status: 0-Preparing, 1-Confirmed, 2-Shipped, 3-Rented, 4-Returned, 5-Completed');
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('order_id')->references('id')->on('orders')->onDelete('restrict');
			$table->foreign('product_id')->references('id')->on('products')->onDelete('restrict');
		});
		
		// Product Schedule
		Schema::create('product_schedules', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('product_id');
			$table->unsignedBigInteger('order_detail_id')->nullable()->comment('Optional for Rental');
			$table->date('short_date')->nullable();
			$table->date('full_date')->nullable();
			$table->text('note')->nullable();
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('product_id')->references('id')->on('products')->onDelete('restrict');
			$table->foreign('order_detail_id')->references('id')->on('order_details')->onDelete('restrict');
		});
		
		// Income
		Schema::create('incomes', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('user_id');
			$table->unsignedBigInteger('order_detail_id');
			$table->decimal('percent', 5, 2)->nullable();
			$table->decimal('amount', 15, 2)->default(0);
			$table->decimal('tax', 15, 2)->default(0);
			$table->decimal('total_amount', 15, 2)->default(0);
			$table->unsignedSmallInteger('status')->default(0)->comment('Status: 0-Pending, 1-PartiallyPaid, 2-Completed');
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('user_id')->references('id')->on('users')->onDelete('restrict');
			$table->foreign('order_detail_id')->references('id')->on('order_details')->onDelete('restrict');
		});
		
		// Withdrawal
		Schema::create('withdrawals', function (Blueprint $table) {
			$table->id();
			$table->string('code');
			$table->unsignedBigInteger('user_id');
			$table->decimal('amount', 15, 2)->default(0);
			$table->decimal('fee', 15, 2)->default(0);
			$table->decimal('total_amount', 15, 2)->default(0);
			$table->tinyText('note')->nullable();
			$table->unsignedSmallInteger('status')->default(0)->comment('Status: 0-Pending, 1-Processed, 2-Canceled');
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('user_id')->references('id')->on('users')->onDelete('restrict');
		});
		
		// Payment
		Schema::create('payments', function (Blueprint $table) {
			$table->id();
			$table->string('code');
			$table->unsignedSmallInteger('type')->default('0')->comment('Type: 0-StorageFee, 1-RentalFee, 2-ProfitWithdrawals');
			$table->unsignedBigInteger('product_id')->nullable()->comment('Optional for Storage');
			$table->unsignedBigInteger('order_id')->nullable()->comment('Optional for Rental');
			$table->unsignedBigInteger('withdrawal_id')->nullable()->comment('Optional for ProfitWithdrawals');
			
			$table->unsignedBigInteger('payer_user_id')->nullable()->comment('Optional for Storage and Rental');
			$table->unsignedBigInteger('payer_user_card_id')->nullable()->comment('Optional for Storage and Rental');
			
			$table->unsignedBigInteger('recipient_user_id')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->unsignedBigInteger('recipient_user_card_id')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_bank_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_bank_code')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_bank_branch_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_bank_branch_code')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_bank_account_type')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_bank_account_number')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_bank_holder_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_pay_jp_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_pay_jp_email')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_pay_jp_phone_number')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_pay_jp_code')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_stripe_name')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_stripe_email')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_stripe_phone_number')->nullable()->comment('Optional for ProfitWithdrawals');
			$table->string('recipient_stripe_code')->nullable()->comment('Optional for ProfitWithdrawals');
			
			$table->string('provider');
			$table->string('customer')->nullable();
			$table->string('funding')->nullable();
			$table->string('brand')->nullable();
			$table->string('network')->nullable();
			$table->string('country')->nullable();
			$table->string('last4')->nullable();
			$table->string('exp_month')->nullable();
			$table->string('exp_year')->nullable();
			$table->string('failure_code')->nullable();
			$table->string('failure_message')->nullable();
			
			$table->decimal('total', 15, 2)->nullable();
			$table->decimal('amount_captured', 15, 2)->nullable();
			$table->decimal('amount_refunded', 15, 2)->nullable();
			$table->decimal('application_fee', 15, 2)->nullable();
			$table->decimal('application_fee_amount', 15, 2)->nullable();
			$table->string('currency')->nullable();
			$table->longText('content')->nullable();
			$table->longText('customer_info')->nullable();
			$table->longText('error_content')->nullable();
			$table->dateTime('finished_at')->nullable();
			$table->smallInteger('status')->default(0)->comment('Status: 0-Pending, 1-Completed, 2-Failed');
			$table->timestamps();
			$table->softDeletes();
			
			// Foreign key constraints
			$table->foreign('product_id')->references('id')->on('products')->onDelete('restrict');
			$table->foreign('order_id')->references('id')->on('orders')->onDelete('restrict');
			$table->foreign('withdrawal_id')->references('id')->on('withdrawals')->onDelete('restrict');
			$table->foreign('payer_user_id')->references('id')->on('users')->onDelete('set null');
			$table->foreign('payer_user_card_id')->references('id')->on('user_cards')->onDelete('set null');
			$table->foreign('recipient_user_id')->references('id')->on('users')->onDelete('set null');
			$table->foreign('recipient_user_card_id')->references('id')->on('user_cards')->onDelete('set null');
		});

		Schema::create('templates', function (Blueprint $table) {
			$table->id();
			$table->string('name');
			$table->smallInteger('type')->default(0);
			$table->tinyText('description')->nullable();
			$table->string('title')->nullable();
			$table->longText('content')->nullable();
			$table->foreignId('user_id')->constrained();
			$table->smallInteger('group')->default(0);
			$table->smallInteger('is_activated')->default(1);
			$table->smallInteger('is_deleted')->default(0);
			$table->timestamps();
		});

		Schema::create('template_attachments', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('template_id');
			$table->string('title');
			$table->string('file_name');
			$table->string('file_type');
			$table->string('file_size');
			$table->string('file_extension');
			$table->timestamps();
			
			$table->foreign('template_id')->references('id')->on('templates')->onDelete('cascade');
		});*/
	}
	
	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		/*Schema::dropIfExists('payments');
		Schema::dropIfExists('withdrawals');
		Schema::dropIfExists('incomes');
		Schema::dropIfExists('order_details');
		Schema::dropIfExists('orders');
		Schema::dropIfExists('user_face_swaps');
		Schema::dropIfExists('user_delivery_addresses');
		Schema::dropIfExists('user_cards');
		Schema::dropIfExists('product_accessories');
		Schema::dropIfExists('product_scenes');
		Schema::dropIfExists('product_colors');
		Schema::dropIfExists('product_categories');
		Schema::dropIfExists('product_schedules');
		Schema::dropIfExists('product_images');
		Schema::dropIfExists('products');
		Schema::dropIfExists('accessories');
		Schema::dropIfExists('scenes');
		Schema::dropIfExists('colors');
		Schema::dropIfExists('categories');
		Schema::dropIfExists('template_attachments');
		Schema::dropIfExists('templates');
		Schema::dropIfExists('users');*/
	}
}
