<?php

namespace Database\Seeders;

use App\Domain\Organization\Models\Branch;
use App\Domain\Organization\Models\Company;
use App\Domain\Organization\Models\CostCenter;
use App\Domain\Organization\Models\Department;
use Illuminate\Database\Seeder;

/**
 * Default company, head-office branch, departments and cost centers (§123).
 * Real values are expected to be edited in the admin UI after install.
 */
class OrganizationSeeder extends Seeder
{
    public function run(): void
    {
        $company = Company::updateOrCreate(
            ['code' => config('mams.default_company_code', 'AT')],
            [
                'name' => env('COMPANY_NAME', 'Asiatic Talents'),
                'legal_name' => env('COMPANY_LEGAL_NAME', 'M/s. Asiatic Talents'),
                // The BMET recruiting licence, shown publicly (§172).
                'license_number' => env('COMPANY_LICENSE', 'RL-1381'),
                'email' => env('COMPANY_EMAIL', 'asiatictalents@gmail.com'),
                'phone' => env('COMPANY_PHONE', '+88 02 9515835'),
                'address' => env(
                    'COMPANY_ADDRESS',
                    'Suite No. 08, Mahtab Center, 177 Shahid Syed Nazrul Islam Saroni, '.
                    'Bijoy Nagar, Dhaka-1000, Bangladesh',
                ),
                'country' => 'BD',
                'base_currency' => 'BDT',
                'timezone' => 'Asia/Dhaka',
                'is_active' => true,
            ],
        );

        $branch = Branch::updateOrCreate(
            ['company_id' => $company->id, 'code' => 'DHK'],
            [
                'name' => 'Head Office — Bijoy Nagar',
                'address' => 'Suite No. 08, Mahtab Center, 177 Shahid Syed Nazrul Islam Saroni, Bijoy Nagar',
                'city' => 'Dhaka',
                'district' => 'Dhaka',
                'postal_code' => '1000',
                'country' => 'BD',
                'phone' => '+88 02 9515835',
                'email' => 'asiatictalents@gmail.com',
                'applicant_ref_prefix' => 'DHK',
                'is_head_office' => true,
                'is_active' => true,
            ],
        );

        $departments = [
            'MGT' => 'Management',
            'REC' => 'Recruitment',
            'PRO' => 'Processing',
            'DOC' => 'Document Verification',
            'ACC' => 'Accounts',
            'HR' => 'Human Resources',
            'SUP' => 'Support',
        ];

        foreach ($departments as $code => $name) {
            Department::updateOrCreate(
                ['company_id' => $company->id, 'code' => $code],
                ['branch_id' => $branch->id, 'name' => $name, 'is_active' => true],
            );
        }

        CostCenter::updateOrCreate(
            ['company_id' => $company->id, 'code' => 'GEN'],
            ['branch_id' => $branch->id, 'name' => 'General', 'is_active' => true],
        );
    }
}
