<?php

namespace App\Http\Controllers;

use App\Models\Dictionary\District;
use Illuminate\Http\Request;

class DistrictController extends Controller
{
    public function index()
    {
        return District::all();
    }

    public function store(Request $request)
    {
        $request->validate([
            'name' => ['required'],
        ]);

        return District::create($request->validated());
    }

    public function show(District $district)
    {
        return $district;
    }

    public function update(Request $request, District $district)
    {
        $request->validate([
            'name' => ['required'],
        ]);

        $district->update($request->validated());

        return $district;
    }

    public function destroy(District $district)
    {
        $district->delete();

        return response()->json();
    }
}
