<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use DB;
use Illuminate\Support\Carbon;

class CoaTypeSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $cek = DB::table('coa_type')->where("account_sub_type","OEXP")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'OEXP',
                    'account_type' => 'Other Expense'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","DEPR")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'DEPR',
                    'account_type' => 'Other Expense'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","OINC")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'OINC',
                    'account_type' => 'Other Revenue'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","EXPS")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'EXPS',
                    'account_type' => 'Expense'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","COGS")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'COGS',
                    'account_type' => 'COGS'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","REVE")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'REVE',
                    'account_type' => 'Sales'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","EQTY")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'EQTY',
                    'account_type' => 'Equity'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","LTLY")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'LTLY',
                    'account_type' => 'Other Expense'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","OCLY")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'OCLY',
                    'account_type' => 'Other Expense'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","APAY")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'APAY',
                    'account_type' => 'Payable'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","FASS")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'FASS',
                    'account_type' => 'Asset'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","OCAS")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'OCAS',
                    'account_type' => 'Asset'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","BANK")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'BANK',
                    'account_type' => 'Asset'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","AREC")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'AREC',
                    'account_type' => 'Sales'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","INTR")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'INTR',
                    'account_type' => 'Equity'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","Cash")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'Cash',
                    'account_type' => 'Cash & Bank'
                ]
            ]);
        }

        $cek = DB::table('coa_type')->where("account_sub_type","Bank")->count();
        if($cek == 0){
            DB::table('coa_type')->insert([
                [
                    'account_sub_type' => 'Bank',
                    'account_type' => 'Cash & Bank'
                ]
            ]);
        }

        $cek = DB::table('periode')->where('periode_code', '2025Q1')->count();
        if ($cek == 0) {
            DB::table('periode')->insert([
                [
                    'periode_code'   => '2025Q1',
                    'periode_start'  => '2025-08-01',
                    'periode_end'    => '2025-08-31',
                    'periode_active' => 'active',
                    'closed_by'      => null,
                    'closed_at'      => null,
                    'created_at'     => Carbon::now(),
                    'updated_at'     => Carbon::now(),
                ],
            ]);
        }
    }
}
