<?php

namespace App\Http\Controllers\Info;

use App\Http\Controllers\Controller;
use App\Models\Info\Brand;
use App\Models\Info\ItemDescription;
use App\Models\Info\SizeRange;
use App\Models\Info\Color; // Current model
use App\Models\Info\FabricComposition;
use App\Models\Info\FabricType;
use App\Models\Info\YarnCount;
use App\Models\Info\FabricWeight;
use App\Models\Info\PortOfLanding;
use App\Models\Info\CountryOfOrigin;
use App\Models\Info\PortOfDischarge;
use App\Models\Info\FinalDestination;
use App\Models\Info\DeliveryTerm;
use App\Models\Info\ShipmentMode;
use App\Models\Info\PaymentTerm;
use App\Models\Info\PaymentMode;

use Illuminate\Http\Request;

class BrandController extends Controller
{

public function index()
{
$brands = Brand::latest()->paginate(10);
        $descriptions = ItemDescription::latest()->paginate(10);
        $sizeRanges = SizeRange::latest()->paginate(10);
        $colors = Color::latest()->paginate(10); // Current entity data
        $fabricCompositions = FabricComposition::latest()->paginate(10);
        $fabricTypes = FabricType::latest()->paginate(10);
        $yarnCounts = YarnCount::latest()->paginate(10);
        $fabricWeights = FabricWeight::latest()->paginate(10);
        $portOfLandings = PortOfLanding::latest()->paginate(10);
        $countryOfOrigins = CountryOfOrigin::latest()->paginate(10);
        $portOfDischarges = PortOfDischarge::latest()->paginate(10);
        $finalDestinations = FinalDestination::latest()->paginate(10);
        $deliveryTerms = DeliveryTerm::latest()->paginate(10);
        $shipmentModes = ShipmentMode::latest()->paginate(10);
        $paymentTerms = PaymentTerm::latest()->paginate(10);
        $paymentModes = PaymentMode::latest()->paginate(10);


return view('admin.info.index', compact(
            'brands', 
            'descriptions', 
            'sizeRanges', 
            'colors', 
            'fabricCompositions', 
            'fabricTypes', 
            'yarnCounts', 
            'fabricWeights', 
            'portOfLandings', 
            'countryOfOrigins', 
            'portOfDischarges', 
            'finalDestinations', 
            'deliveryTerms', 
            'shipmentModes', 
            'paymentTerms', 
            'paymentModes'
        ));}

public function update(Request $request, Brand $brand)
{
    $request->validate(['name' => 'required|string|max:255']);
    $brand->update(['name' => $request->name]);
    return back()->with('success', 'Brand updated successfully.');
}

public function store(Request $request)
{
    $request->validate(['name' => 'required|string|max:255']);
    Brand::create(['name' => $request->name]);
    return back()->with('success', 'Brand added successfully.');
}

public function destroy(Brand $brand)
{
    $brand->delete();
    return back()->with('success', 'Brand deleted.');
}

}
