<?php

namespace Database\Seeders;

use App\Models\User;
use App\Models\Client;
use App\Models\Installation;
use App\Models\Camera;
use App\Models\Contract;
use App\Models\Ticket;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Carbon\Carbon;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // Require explicit namespace resolution inside run
        
        // Create Admin
        $admin = User::create([
            'name' => 'Admin Silva',
            'email' => 'admin@securevision.com',
            'password' => Hash::make('password'),
            'role' => 'Admin',
        ]);

        // Create Client
        $clientUser = User::create([
            'name' => 'Empresa XPTO',
            'email' => 'cliente@xpto.com',
            'password' => Hash::make('password'),
            'role' => 'Client',
        ]);

        $client = Client::create([
            'user_id' => $clientUser->id,
            'name' => 'Empresa XPTO, Lda',
            'document_number' => '501234567',
            'phone' => '+351 912 345 678',
            'address' => 'Lisboa, Centro',
        ]);

        // Create Installation
        $installation = Installation::create([
            'client_id' => $client->id,
            'address' => 'Armazém XPTO - Parque das Nações',
            'status' => 'active',
            'installation_date' => Carbon::now()->subMonths(2),
        ]);

        // Create Cameras
        Camera::create([
            'installation_id' => $installation->id,
            'name' => 'Cam 01 - Entrada',
            'model' => 'Hikvision 4K HDR',
            'ip_address' => '192.168.1.100',
        ]);
        Camera::create([
            'installation_id' => $installation->id,
            'name' => 'Cam 02 - Corredor',
            'model' => 'Hikvision 4K HDR',
            'ip_address' => '192.168.1.101',
        ]);

        // Create Contract
        Contract::create([
            'client_id' => $client->id,
            'installation_id' => $installation->id,
            'start_date' => Carbon::now()->subMonths(2),
            'end_date' => Carbon::now()->addMonths(10),
            'monthly_fee' => 150.00,
            'status' => 'active',
        ]);

        // Create Ticket
        Ticket::create([
            'client_id' => $client->id,
            'installation_id' => $installation->id,
            'subject' => 'Câmera Parou de Gravar',
            'description' => 'A câmera 02 do corredor não está a emitir sinal de vídeo desde as 10h da manhã.',
            'status' => 'open',
            'priority' => 'high',
        ]);
    }
}
