<?php

namespace Database\Seeders;

use App\Models\CompanySetting;
use App\Models\EmailConfiguration;
use App\Models\ExpenseSetting;
use App\Models\InvoiceNumberingSetting;
use App\Models\QuotationSetting;
use App\Models\SmsConfiguration;
use App\Models\WhatsAppConfiguration;
use Illuminate\Database\Seeder;

class CompanySettingSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Company Settings
        CompanySetting::updateOrCreate(
            ['id' => 1],
            [
                'company_name' => 'ProInvoice Technologies Inc.',
                'company_email' => 'info@proinvoice.com',
                'company_phone' => '+1 (555) 123-4567',
                'company_address' => '123 Business Center, Suite 500',
                'company_city' => 'New York',
                'company_state' => 'NY',
                'company_zip' => '10001',
                'company_country' => 'United States',
                'company_tax_id' => 'US12-3456789',
                'company_registration_number' => 'REG-2024-001234',
                'company_notes' => 'Professional invoicing and business management solutions.',
            ]
        );

        // Invoice Numbering Settings
        InvoiceNumberingSetting::updateOrCreate(
            ['id' => 1],
            [
                'prefix' => 'INV',
                'next_number' => 26,
                'number_length' => 6,
                'format' => '{prefix}-{number}',
                'reset_yearly' => false,
            ]
        );

        // Quotation Settings
        QuotationSetting::updateOrCreate(
            ['id' => 1],
            [
                'prefix' => 'QUO',
                'next_number' => 26,
                'number_length' => 6,
                'format' => '{prefix}-{number}',
                'validity_days' => 30,
                'terms' => 'This quotation is valid for 30 days from the date of issue. Prices are subject to change without notice after the validity period. All payments should be made according to the agreed terms. Additional terms and conditions may apply based on the specific project requirements.',
                'notes' => 'Thank you for considering our services. We look forward to working with you. Please feel free to contact us if you have any questions or require any modifications to this quotation.',
            ]
        );

        // Expense Settings
        ExpenseSetting::updateOrCreate(
            ['id' => 1],
            [
                'require_approval' => true,
                'approval_threshold' => 1000.00,
                'default_categories' => json_encode([
                    'Office Supplies',
                    'Travel',
                    'Utilities',
                    'Software',
                    'Marketing',
                    'Professional Services',
                    'Equipment',
                    'Insurance',
                    'Rent',
                    'Maintenance',
                    'Telecommunications',
                    'Training',
                    'Meals & Entertainment',
                    'Subscriptions',
                    'Miscellaneous',
                ]),
                'notes' => 'Expenses above $1,000 require manager approval.',
            ]
        );

        // Email Configuration
        EmailConfiguration::updateOrCreate(
            ['id' => 1],
            [
                'mailer' => 'smtp',
                'host' => 'smtp.example.com',
                'port' => 587,
                'username' => 'noreply@proinvoice.com',
                'password' => '', // Should be set in production
                'encryption' => 'tls',
                'from_address' => 'noreply@proinvoice.com',
                'from_name' => 'ProInvoice',
                'is_active' => true,
            ]
        );

        // SMS Configuration
        SmsConfiguration::updateOrCreate(
            ['id' => 1],
            [
                'provider' => 'twilio',
                'api_key' => '', // Should be set in production
                'api_secret' => '', // Should be set in production
                'sender_id' => 'ProInvoice',
                'config' => json_encode([
                    'account_sid' => '',
                    'region' => 'us1',
                ]),
                'is_active' => false,
            ]
        );

        // WhatsApp Configuration
        WhatsAppConfiguration::updateOrCreate(
            ['id' => 1],
            [
                'provider' => 'twilio',
                'api_key' => '', // Should be set in production
                'api_secret' => '', // Should be set in production
                'phone_number_id' => '',
                'business_account_id' => '',
                'config' => json_encode([
                    'webhook_url' => '',
                    'verify_token' => '',
                ]),
                'is_active' => false,
            ]
        );
    }
}
