<?php

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

/**
 * Migration: Partnership and Collaboration Portal - Partner Contacts Table
 * 
 * Stores contact persons for partner organizations.
 * Supports multiple contacts per partner with role designation.
 * 
 * @author SSHIA Development Team
 * @version 1.0.0
 */
return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('r_partner_contacts', function (Blueprint $table) {
            // Primary Key
            $table->id();
            
            // Foreign Key to Partner
            $table->foreignId('partner_id')
                  ->constrained('r_partners')
                  ->onDelete('cascade')
                  ->comment('Associated partner organization');
            
            // Contact Information
            $table->string('name', 191)
                  ->comment('Contact person name');
            
            $table->string('title', 191)
                  ->nullable()
                  ->comment('Job title/position');
            
            $table->string('email', 191)
                  ->nullable()
                  ->comment('Contact email');
            
            $table->string('phone', 50)
                  ->nullable()
                  ->comment('Direct phone number');
            
            $table->string('mobile', 50)
                  ->nullable()
                  ->comment('Mobile phone number');
            
            // Role
            $table->enum('role', [
                'primary_contact', 
                'executive', 
                'technical', 
                'administrative', 
                'communications', 
                'other'
            ])->default('primary_contact')->comment('Contact role');
            
            $table->boolean('is_primary')
                  ->default(false)
                  ->comment('Primary contact for organization');
            
            // Status
            $table->boolean('is_active')
                  ->default(true)
                  ->comment('Active contact status');
            
            // Notes
            $table->text('notes')
                  ->nullable()
                  ->comment('Additional notes');
            
            // Timestamps
            $table->timestamps();
            
            // Indexes
            $table->index('partner_id');
            $table->index('is_primary');
            $table->index('role');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('r_partner_contacts');
    }
};
