<?php

namespace Kylin\LawCase\Policies;

use Kylin\LawCase\Models\CaseModel;
use App\Models\User;

class CasePolicy
{
    /**
     * 查看案件 - 仅案件成员或管理员可查看
     */
    public function view(User $user, CaseModel $case): bool
    {
        if ($user->hasRole('super_admin') || $user->hasRole('partner')) {
            return true;
        }

        return $case->principal_lawyer_id === $user->id
            || $case->assistant_lawyer_id === $user->id
            || $case->lawyers()->where('user_id', $user->id)->exists();
    }

    /**
     * 更新案件
     */
    public function update(User $user, CaseModel $case): bool
    {
        if ($user->hasRole('super_admin') || $user->hasRole('partner')) {
            return true;
        }

        return $case->principal_lawyer_id === $user->id;
    }

    /**
     * 删除案件 - 仅管理员
     */
    public function delete(User $user, CaseModel $case): bool
    {
        return $user->hasRole('super_admin');
    }
}
