<?php

namespace App\Policies;

use App\Models\Supplier;
use App\Models\User;

class SupplierPolicy
{
    // SIAPA BOLEH LIHAT DAFTAR SUPPLIER?
    // Owner BOLEH, Admin Cabang BOLEH (supaya bisa pilih supplier saat pembelian)
    public function viewAny(User $user): bool
    {
        return in_array($user->role, ['owner', 'admin_cabang']);
    }

    // SIAPA BOLEH TAMBAH SUPPLIER BARU?
    // HANYA OWNER (Agar tidak ada data ganda)
    public function create(User $user): bool
    {
        return $user->role === 'owner';
    }

    // SIAPA BOLEH EDIT DATA SUPPLIER?
    // HANYA OWNER
    public function update(User $user, Supplier $supplier): bool
    {
        return $user->role === 'owner';
    }

    // SIAPA BOLEH HAPUS SUPPLIER?
    // HANYA OWNER
    public function delete(User $user, Supplier $supplier): bool
    {
        return $user->role === 'owner';
    }
}