<?php

namespace Database\Seeders;

use App\Models\Bidding\Bidding;
use App\Models\Tenants\Tenant;
use Illuminate\Database\Seeder;

class BiddingSeeder extends Seeder
{
    /**
     * 입찰 더미데이터 10건 Seed
     * React 목업 데이터 기준
     */
    public function run(): void
    {
        // 첫 번째 테넌트 ID 가져오기
        $tenant = Tenant::first();
        if (! $tenant) {
            $this->command->warn('테넌트가 없습니다. TenantSeeder를 먼저 실행하세요.');

            return;
        }

        $tenantId = $tenant->id;

        $biddings = [
            [
                'bidding_code' => 'BID-2025-001',
                'client_name' => '이사대표',
                'project_name' => '광장 아파트',
                'bidding_date' => '2025-01-25',
                'total_count' => 15,
                'bidding_amount' => 71000000,
                'bid_date' => '2025-01-20',
                'submission_date' => '2025-01-22',
                'confirm_date' => '2025-01-25',
                'status' => 'awarded',
                'bidder_name' => '홍길동',
                'remarks' => '',
            ],
            [
                'bidding_code' => 'BID-2025-002',
                'client_name' => '야사건설',
                'project_name' => '대림아파트',
                'bidding_date' => '2025-01-20',
                'total_count' => 22,
                'bidding_amount' => 100000000,
                'bid_date' => '2025-01-18',
                'submission_date' => null,
                'confirm_date' => null,
                'status' => 'waiting',
                'bidder_name' => '김철수',
                'remarks' => '',
            ],
            [
                'bidding_code' => 'BID-2025-003',
                'client_name' => '여의건설',
                'project_name' => '현장아파트',
                'bidding_date' => '2025-01-18',
                'total_count' => 18,
                'bidding_amount' => 85000000,
                'bid_date' => '2025-01-15',
                'submission_date' => '2025-01-16',
                'confirm_date' => '2025-01-18',
                'status' => 'awarded',
                'bidder_name' => '홍길동',
                'remarks' => '',
            ],
            [
                'bidding_code' => 'BID-2025-004',
                'client_name' => '이사대표',
                'project_name' => '송파타워',
                'bidding_date' => '2025-01-15',
                'total_count' => 30,
                'bidding_amount' => 120000000,
                'bid_date' => '2025-01-12',
                'submission_date' => '2025-01-13',
                'confirm_date' => '2025-01-15',
                'status' => 'failed',
                'bidder_name' => '이영희',
                'remarks' => '가격 경쟁력 부족',
            ],
            [
                'bidding_code' => 'BID-2025-005',
                'client_name' => '야사건설',
                'project_name' => '강남센터',
                'bidding_date' => '2025-01-12',
                'total_count' => 25,
                'bidding_amount' => 95000000,
                'bid_date' => '2025-01-10',
                'submission_date' => '2025-01-11',
                'confirm_date' => null,
                'status' => 'submitted',
                'bidder_name' => '홍길동',
                'remarks' => '',
            ],
            [
                'bidding_code' => 'BID-2025-006',
                'client_name' => '여의건설',
                'project_name' => '목동센터',
                'bidding_date' => '2025-01-10',
                'total_count' => 12,
                'bidding_amount' => 78000000,
                'bid_date' => '2025-01-08',
                'submission_date' => '2025-01-09',
                'confirm_date' => '2025-01-10',
                'status' => 'invalid',
                'bidder_name' => '김철수',
                'remarks' => '입찰 조건 미충족',
            ],
            [
                'bidding_code' => 'BID-2025-007',
                'client_name' => '이사대표',
                'project_name' => '서초타워',
                'bidding_date' => '2025-01-08',
                'total_count' => 35,
                'bidding_amount' => 150000000,
                'bid_date' => '2025-01-05',
                'submission_date' => null,
                'confirm_date' => null,
                'status' => 'waiting',
                'bidder_name' => '이영희',
                'remarks' => '',
            ],
            [
                'bidding_code' => 'BID-2025-008',
                'client_name' => '야사건설',
                'project_name' => '청담프로젝트',
                'bidding_date' => '2025-01-05',
                'total_count' => 40,
                'bidding_amount' => 200000000,
                'bid_date' => '2025-01-03',
                'submission_date' => '2025-01-04',
                'confirm_date' => '2025-01-05',
                'status' => 'awarded',
                'bidder_name' => '홍길동',
                'remarks' => '',
            ],
            [
                'bidding_code' => 'BID-2025-009',
                'client_name' => '여의건설',
                'project_name' => '잠실센터',
                'bidding_date' => '2025-01-03',
                'total_count' => 20,
                'bidding_amount' => 88000000,
                'bid_date' => '2025-01-01',
                'submission_date' => null,
                'confirm_date' => null,
                'status' => 'hold',
                'bidder_name' => '김철수',
                'remarks' => '검토 대기 중',
            ],
            [
                'bidding_code' => 'BID-2025-010',
                'client_name' => '이사대표',
                'project_name' => '역삼빌딩',
                'bidding_date' => '2025-01-01',
                'total_count' => 10,
                'bidding_amount' => 65000000,
                'bid_date' => '2024-12-28',
                'submission_date' => null,
                'confirm_date' => null,
                'status' => 'waiting',
                'bidder_name' => '이영희',
                'remarks' => '',
            ],
        ];

        foreach ($biddings as $data) {
            Bidding::create([
                'tenant_id' => $tenantId,
                'bidding_code' => $data['bidding_code'],
                'client_name' => $data['client_name'],
                'project_name' => $data['project_name'],
                'bidding_date' => $data['bidding_date'],
                'total_count' => $data['total_count'],
                'bidding_amount' => $data['bidding_amount'],
                'bid_date' => $data['bid_date'],
                'submission_date' => $data['submission_date'],
                'confirm_date' => $data['confirm_date'],
                'status' => $data['status'],
                'bidder_name' => $data['bidder_name'],
                'remarks' => $data['remarks'],
                'vat_type' => 'excluded',
                'created_by' => 1,
            ]);
        }

        $this->command->info('입찰 더미데이터 10건이 생성되었습니다.');
        $this->command->info('- waiting: 3건 (BID-002, 007, 010)');
        $this->command->info('- awarded: 3건 (BID-001, 003, 008)');
        $this->command->info('- submitted: 1건 (BID-005)');
        $this->command->info('- failed: 1건 (BID-004)');
        $this->command->info('- invalid: 1건 (BID-006)');
        $this->command->info('- hold: 1건 (BID-009)');
    }
}
